api.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. """PACC API functions"""
  2. import re
  3. import requests
  4. from bs4 import BeautifulSoup
  5. from dateutil import parser
  6. from app import BASE_URL, HEADERS
  7. def get_rr_account(account_id):
  8. """Get Rival Region account"""
  9. response = requests.get(
  10. '{}slide/profile/{}'.format(BASE_URL, account_id),
  11. headers=HEADERS
  12. )
  13. soup = BeautifulSoup(response.text, 'html.parser')
  14. account = {
  15. 'name': None,
  16. 'region': None,
  17. 'residency': None,
  18. 'registation_date': None,
  19. }
  20. table = soup.find('table')
  21. name = soup.find('h1')
  22. if name:
  23. account['name'] = re.sub(r'.*:\s', '', name.text)
  24. print(account['name'])
  25. for row in table.find_all('tr'):
  26. label = row.find('td').text.strip()
  27. if label == 'Region:':
  28. span = row.find('span', {'class': 'dot'})
  29. if span:
  30. account['region'] = span.text
  31. if label == 'Residency:':
  32. span = row.find('span', {'class': 'dot'})
  33. if span:
  34. account['residency'] = span.text
  35. if label == 'Registration date:':
  36. element = row.find('td', {'class': 'imp'})
  37. if element:
  38. account['registation_date'] = parser.parse(element.text)
  39. # print(region)
  40. return account