account.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import logging
  2. import secrets
  3. import time
  4. import uuid
  5. from collections import OrderedDict
  6. from pathlib import Path
  7. import httpx
  8. import requests
  9. class OrnaAccount:
  10. domain = 'https://playorna.com/api'
  11. def __init__(self, config):
  12. self.config = config
  13. self.username = config['username']
  14. self.password = config['password']
  15. self.proxy = config['proxy']
  16. self.useragent = config['useragent']
  17. # Apply headers
  18. self.headers_get = OrderedDict(
  19. [
  20. ('accept', "application/json, text/plain, */*"),
  21. ('cache-control', 'no-cache'),
  22. ('x-orna-sid', config['x-orna-sid']),
  23. ('x-orna-version', config['x-orna-version']),
  24. ('user-agent', config['useragent']),
  25. ('x-requested-with', config['x-requested-with']),
  26. ('sec-fetch-site', config['sec-fetch-site']),
  27. ('sec-fetch-mode', config['sec-fetch-mode']),
  28. ('sec-fetch-dest', config['sec-fetch-dest']),
  29. ('accept-encoding', 'gzip, deflate'),
  30. ('accept-language', 'en-US,en;q=0.9'),
  31. ]
  32. )
  33. self.headers_post = OrderedDict(
  34. [
  35. ('content-length', ''),
  36. ('accept', 'application/json, text/plain, */*'),
  37. ('cache-control', 'no-cache'),
  38. ('origin', 'file://'),
  39. ('x-orna-sid', config['x-orna-sid']),
  40. ('user-agent', config['useragent']),
  41. ('content-type', ''),
  42. ('x-requested-with', config['x-requested-with']),
  43. ('sec-fetch-site', config['sec-fetch-site']),
  44. ('sec-fetch-mode', config['sec-fetch-mode']),
  45. ('sec-fetch-dest', config['sec-fetch-dest']),
  46. ('accept-encoding', 'gzip, deflate'),
  47. ('accept-language', 'en-US,en;q=0.9'),
  48. ]
  49. )
  50. # Setup logger
  51. self.logger = logging.getLogger('ornauto.account')
  52. if (self.proxy != '') and Path.is_file(Path('charles.pem')):
  53. self.session = httpx.Client(
  54. http2=True,
  55. proxies={
  56. "http://": self.proxy,
  57. "https://": self.proxy,
  58. },
  59. verify=False
  60. # verify='charles.pem'
  61. # verify='mitmproxy-ca-cert.pem'
  62. )
  63. else:
  64. self.session = httpx.Client(http2=True)
  65. # Set headers
  66. self.session.headers = self.headers_get
  67. # GET
  68. def get(self, url, params={}, referer='', headers={}):
  69. if url[0] == '/':
  70. url = self.domain + url
  71. if referer != '':
  72. if referer[0] == '/':
  73. referer = self.domain + referer
  74. headers['Referer'] = referer
  75. params['x'] = int(time.time_ns() / 1000000)
  76. params['lang'] = 'en'
  77. result = self.session.get(url, params=params, headers=headers)
  78. self.session.cookies.clear()
  79. return result
  80. # POST
  81. def post(self, url, data={}, params={}, referer='', headers={}):
  82. # headers['origin'] = "file://"
  83. if url[0] == '/':
  84. url = self.domain + url
  85. if referer != '':
  86. if referer[0] == '/':
  87. referer = self.domain + referer
  88. headers['Referer'] = referer
  89. # self.session.headers # start here
  90. params['x'] = int(time.time_ns() / 1000000)
  91. # params['lang'] = 'en'
  92. data['lang'] = 'en'
  93. result = self.session.post(url, params=params, data=data, headers=headers)
  94. self.session.cookies.clear()
  95. return result