refresh_address.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import requests
  2. import pymysql
  3. # from app import crud
  4. # from app.api import deps
  5. pymysql.install_as_MySQLdb()
  6. import dataset
  7. import requests
  8. import json
  9. import qrcode
  10. baseUrl = "https://nft-api-staging.joyso.io/api/v1/"
  11. headers = {
  12. 'Authorization':
  13. 'Basic %s' % 'bmZ0OmMxOTEzOWMzYjM3YjdjZWU3ZmY3OTFiZGU3NzdjZWNl'
  14. }
  15. db = dataset.connect(
  16. 'mysql://choozmo:pAssw0rd@db.ptt.cx:3306/arkcard?charset=utf8mb4'
  17. )
  18. table = db.query('select * from users')
  19. # result1 = table.find_one(userid=real_user_id)
  20. for i in table:
  21. if i.get('userid'):
  22. user_id = i.get('userid')
  23. data = 'uid=' + user_id
  24. r = requests.post(url=baseUrl + 'accounts', headers=headers, data=data)
  25. # extract the account address
  26. dict_str = json.loads(r.text)
  27. user_account = dict_str['account']
  28. user_address = user_account['address']
  29. # generate qr code from user id
  30. qr = qrcode.QRCode(
  31. version=1,
  32. box_size=10,
  33. border=5)
  34. qr.add_data(user_address)
  35. qr.make(fit=True)
  36. img_qr = qr.make_image(fill='black', back_color='white')
  37. filename = "/var/www/ArkCard-Linebot/ArkCard-web/qrcode/" + \
  38. user_id + '.png'
  39. img_qr.save(filename)
  40. db.query('update users set useraddress=\"' + str(user_address) + '\" where id=' + str(i.get('id')))