Advertisement
Guest User

check rank of user and next rank requirements

a guest
Jun 5th, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.64 KB | None | 0 0
  1. from lxml import html
  2. import sys
  3. import re
  4. import requests
  5.  
  6. g_ranks = ['Brand new', 'Newbie', 'Jr Member', 'Member', 'Full Member', 'Sr. Member', 'Hero Member', 'Legendary']
  7. g_merits = [0, 0, 1, 10, 100, 250, 500, 1000]
  8. g_activity = [0, 1, 30, 60, 120, 240, 480, 775]
  9.  
  10. def getProfile(uid):
  11.   cookies = {
  12.     'PHPSESSID': 'xx',
  13.   }
  14.  
  15.   headers = {
  16.     'Accept-Encoding': 'gzip, deflate, br',
  17.     'Accept-Language': 'en-US,en;q=0.8',
  18.     'Upgrade-Insecure-Requests': '1',
  19.     'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36',
  20.     'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  21.     'Cache-Control': 'max-age=0',
  22.     'Connection': 'keep-alive',
  23.     'If-Modified-Since': 'Thu, 27 Jul 2017 18:15:14 GMT',
  24.   }
  25.  
  26.   url = 'https://bitcointalk.org/index.php?action=profile;u=' + uid + ''
  27.   print 'Profile:', url
  28.   page = requests.get(url, headers=headers, cookies=cookies)
  29.   tree = html.fromstring(page.content)
  30.   return tree
  31.  
  32. def getRankFromIndex(index):
  33.   return g_ranks[index]
  34.  
  35. def getRank(rank):
  36.   return g_ranks.index(rank)
  37.  
  38. def getNextRank(rank):
  39.   nextRank = getRank(rank) + 1
  40.   return getRankFromIndex(nextRank)
  41.  
  42. def getMissingRequisites(merits, activity, rank):
  43.   index = getRank(rank)
  44.   missing_merits = g_merits[index] - int(merits)
  45.   missing_activity = g_activity[index] - int(activity)
  46.   return 'Merits:', missing_merits, 'Activity:', missing_activity
  47.  
  48. if __name__ == '__main__':
  49.   uid = sys.argv[1]
  50.   print 'UID', uid
  51.   remerit = re.compile(r"Merit")
  52.   reactivity = re.compile(r"Activity")
  53.   reposition = re.compile(r"Position")
  54.   actual_merits = 0
  55.   actual_posts = 0
  56.   actual_position = ''
  57.  
  58.   tree = getProfile(uid)
  59.  
  60.   try:
  61.     datas = tree.xpath('//td[@class="windowbg"]/table/tr')
  62.     for data in datas:
  63.       title = data.text_content().strip()
  64.  
  65.       if len(remerit.findall(title)) > 0:
  66.         temp = title.split(':')
  67.         actual_merits = temp[1].strip()
  68.  
  69.       if len(reactivity.findall(title)) > 0:
  70.         temp = title.split(':')
  71.         actual_posts = temp[1].strip()
  72.  
  73.       if len(reposition.findall(title)) > 0:
  74.         temp = title.split(':')
  75.         actual_position = temp[1].strip()
  76.  
  77.     print 'Merits:', actual_merits
  78.     print 'Activity:', actual_posts
  79.     print 'Position:', actual_position
  80.     if actual_position != 'Legendary':
  81.       next_position = getNextRank(actual_position)
  82.       print 'Next Position:', next_position
  83.       print 'Missing:', getMissingRequisites(actual_merits, actual_posts, next_position)
  84.   except:
  85.     print 'any error happenD'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement