Advertisement
Guest User

check profile rank v2

a guest
Jun 28th, 2019
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.87 KB | None | 0 0
  1. from lxml import html
  2. import sys
  3. import re
  4. import requests
  5. import math
  6. import datetime
  7.  
  8. g_ranks = ['Brand new', 'Newbie', 'Jr Member', 'Member', 'Full Member', 'Sr. Member', 'Hero Member', 'Legendary']
  9. g_merits = [0, 0, 1, 10, 100, 250, 500, 1000]
  10. g_activity = [0, 1, 30, 60, 120, 240, 480, 775]
  11.  
  12. def getProfile(uid):
  13.   cookies = {
  14.     'PHPSESSID': '4iv9q9mc262v8j3vtmsrjf86r6',
  15.   }
  16.  
  17.   headers = {
  18.     'Accept-Encoding': 'gzip, deflate, br',
  19.     'Accept-Language': 'en-US,en;q=0.8',
  20.     'Upgrade-Insecure-Requests': '1',
  21.     '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',
  22.     'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
  23.     'Cache-Control': 'max-age=0',
  24.     'Connection': 'keep-alive',
  25.     'If-Modified-Since': 'Thu, 27 Jul 2017 18:15:14 GMT',
  26.   }
  27.  
  28.   url = 'https://bitcointalk.org/index.php?action=profile;u=' + uid + ''
  29.   print 'Profile:', url
  30.   print 'UID', uid
  31.   page = requests.get(url, headers=headers, cookies=cookies)
  32.   tree = html.fromstring(page.content)
  33.   return tree
  34.  
  35. def getRankFromIndex(index):
  36.   return g_ranks[index]
  37.  
  38. def getRank(rank):
  39.   return g_ranks.index(rank)
  40.  
  41. def getNextRank(rank):
  42.   nextRank = getRank(rank) + 1
  43.   return getRankFromIndex(nextRank)
  44.  
  45. def getMissingRequisites(merits, activity, rank):
  46.   index = getRank(rank)
  47.   missing_merits = g_merits[index] - int(merits)
  48.   missing_activity = g_activity[index] - int(activity)
  49.   if missing_merits < 0:
  50.     missing_merits = 'FULLFILLED'
  51.   if missing_activity < 0:
  52.     missing_activity = 'FULLFILLED'
  53.   return 'Merits:', missing_merits, 'Activity:', missing_activity
  54.  
  55. def calculateLuck(activity):
  56.   #luckdenominator = math.floor( (1030-775)/14 )
  57.   #lucknumerator = math.floor( (int(activity)-775)/14 ) +1
  58.   #print math.floor(min([lucknumerator/luckdenominator, 1])*100 )
  59.   luck = 100 * 14 / (1030 - int(activity))
  60.   print math.floor(luck)
  61.  
  62. def printProfile(actual_nick, actual_merits, actual_posts, actual_position, actual_registered, actual_lastlogin, actual_email):
  63.   signupdata = datetime.datetime.strptime(actual_registered, '%B %d, %Y, %H')
  64.   lastlogindata = actual_lastlogin
  65.   retoday = re.compile(r"Today")
  66.   if len(retoday.findall(actual_lastlogin)) <= 0:
  67.     lastlogind = datetime.datetime.strptime(actual_lastlogin, '%B %d, %Y, %H')
  68.     lastlogindata = str(lastlogind.date()) + ' ' + str(lastlogind.time())
  69.   print 'Nick:', actual_nick
  70.   print '-----'
  71.   print 'Merits:', actual_merits
  72.   print 'Activity:', actual_posts
  73.   print 'Position:', actual_position
  74.   print '-----'
  75.   print 'SignUp:', signupdata.date(), signupdata.time()
  76.   print 'Last Active:', lastlogindata
  77.   print 'Mail:', actual_email
  78.   print '-----'
  79.  
  80. if __name__ == '__main__':
  81.   uid = sys.argv[1]
  82.   renick = re.compile(r"Name")
  83.   remerit = re.compile(r"Merit")
  84.   reactivity = re.compile(r"Activity")
  85.   reposition = re.compile(r"Position")
  86.   relastlogin = re.compile(r"Last Active")
  87.   resignup = re.compile(r"Date Registered")
  88.   reemail = re.compile(r"Email")
  89.   actual_nick = ''
  90.   actual_merits = 0
  91.   actual_posts = 0
  92.   actual_position = ''
  93.   actual_lastlogin = ''
  94.   actual_registered = ''
  95.   actual_email = ''
  96.  
  97.   tree = getProfile(uid)
  98.  
  99.   try:
  100.     datas = tree.xpath('//td[@class="windowbg"]/table/tr')
  101.     for data in datas:
  102.       title = data.text_content().strip()
  103.  
  104.       if len(renick.findall(title)) > 0:
  105.         temp = title.split(':')
  106.         actual_nick = temp[1].strip()
  107.  
  108.       if len(remerit.findall(title)) > 0:
  109.         temp = title.split(':')
  110.         actual_merits = temp[1].strip()
  111.  
  112.       if len(reactivity.findall(title)) > 0:
  113.         temp = title.split(':')
  114.         actual_posts = temp[1].strip()
  115.  
  116.       if len(reposition.findall(title)) > 0:
  117.         temp = title.split(':')
  118.         actual_position = temp[1].strip()
  119.  
  120.       if len(relastlogin.findall(title)) > 0:
  121.         temp = title.split(':')
  122.         actual_lastlogin = temp[1].strip()
  123.  
  124.       if len(resignup.findall(title)) > 0:
  125.         temp = title.split(':')
  126.         actual_registered = temp[1].strip()
  127.  
  128.       if len(reemail.findall(title)) > 0:
  129.         temp = title.split(':')
  130.         actual_email = temp[1].strip()
  131.  
  132.     printProfile(actual_nick, actual_merits, actual_posts, actual_position, actual_registered, actual_lastlogin, actual_email)
  133.  
  134.     if actual_position != 'Legendary' and actual_position != 'Hero Member':
  135.       next_position = getNextRank(actual_position)
  136.       print 'Next Position:', next_position
  137.       print 'Missing:', getMissingRequisites(actual_merits, actual_posts, next_position)
  138.     if actual_position == 'Hero Member':
  139.       next_position = getNextRank(actual_position)
  140.       print 'Calculate luck'
  141.       calculateLuck(actual_posts)
  142.       print 'Missing:', getMissingRequisites(actual_merits, actual_posts, next_position)
  143.   except Exception as e: print(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement