Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from lxml import html
- import sys
- import re
- import requests
- import math
- import datetime
- g_ranks = ['Brand new', 'Newbie', 'Jr Member', 'Member', 'Full Member', 'Sr. Member', 'Hero Member', 'Legendary']
- g_merits = [0, 0, 1, 10, 100, 250, 500, 1000]
- g_activity = [0, 1, 30, 60, 120, 240, 480, 775]
- def getProfile(uid):
- cookies = {
- 'PHPSESSID': '4iv9q9mc262v8j3vtmsrjf86r6',
- }
- headers = {
- 'Accept-Encoding': 'gzip, deflate, br',
- 'Accept-Language': 'en-US,en;q=0.8',
- 'Upgrade-Insecure-Requests': '1',
- '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',
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
- 'Cache-Control': 'max-age=0',
- 'Connection': 'keep-alive',
- 'If-Modified-Since': 'Thu, 27 Jul 2017 18:15:14 GMT',
- }
- url = 'https://bitcointalk.org/index.php?action=profile;u=' + uid + ''
- print 'Profile:', url
- print 'UID', uid
- page = requests.get(url, headers=headers, cookies=cookies)
- tree = html.fromstring(page.content)
- return tree
- def getRankFromIndex(index):
- return g_ranks[index]
- def getRank(rank):
- return g_ranks.index(rank)
- def getNextRank(rank):
- nextRank = getRank(rank) + 1
- return getRankFromIndex(nextRank)
- def getMissingRequisites(merits, activity, rank):
- index = getRank(rank)
- missing_merits = g_merits[index] - int(merits)
- missing_activity = g_activity[index] - int(activity)
- if missing_merits < 0:
- missing_merits = 'FULLFILLED'
- if missing_activity < 0:
- missing_activity = 'FULLFILLED'
- return 'Merits:', missing_merits, 'Activity:', missing_activity
- def calculateLuck(activity):
- #luckdenominator = math.floor( (1030-775)/14 )
- #lucknumerator = math.floor( (int(activity)-775)/14 ) +1
- #print math.floor(min([lucknumerator/luckdenominator, 1])*100 )
- luck = 100 * 14 / (1030 - int(activity))
- print math.floor(luck)
- def printProfile(actual_nick, actual_merits, actual_posts, actual_position, actual_registered, actual_lastlogin, actual_email):
- signupdata = datetime.datetime.strptime(actual_registered, '%B %d, %Y, %H')
- lastlogindata = actual_lastlogin
- retoday = re.compile(r"Today")
- if len(retoday.findall(actual_lastlogin)) <= 0:
- lastlogind = datetime.datetime.strptime(actual_lastlogin, '%B %d, %Y, %H')
- lastlogindata = str(lastlogind.date()) + ' ' + str(lastlogind.time())
- print 'Nick:', actual_nick
- print '-----'
- print 'Merits:', actual_merits
- print 'Activity:', actual_posts
- print 'Position:', actual_position
- print '-----'
- print 'SignUp:', signupdata.date(), signupdata.time()
- print 'Last Active:', lastlogindata
- print 'Mail:', actual_email
- print '-----'
- if __name__ == '__main__':
- uid = sys.argv[1]
- renick = re.compile(r"Name")
- remerit = re.compile(r"Merit")
- reactivity = re.compile(r"Activity")
- reposition = re.compile(r"Position")
- relastlogin = re.compile(r"Last Active")
- resignup = re.compile(r"Date Registered")
- reemail = re.compile(r"Email")
- actual_nick = ''
- actual_merits = 0
- actual_posts = 0
- actual_position = ''
- actual_lastlogin = ''
- actual_registered = ''
- actual_email = ''
- tree = getProfile(uid)
- try:
- datas = tree.xpath('//td[@class="windowbg"]/table/tr')
- for data in datas:
- title = data.text_content().strip()
- if len(renick.findall(title)) > 0:
- temp = title.split(':')
- actual_nick = temp[1].strip()
- if len(remerit.findall(title)) > 0:
- temp = title.split(':')
- actual_merits = temp[1].strip()
- if len(reactivity.findall(title)) > 0:
- temp = title.split(':')
- actual_posts = temp[1].strip()
- if len(reposition.findall(title)) > 0:
- temp = title.split(':')
- actual_position = temp[1].strip()
- if len(relastlogin.findall(title)) > 0:
- temp = title.split(':')
- actual_lastlogin = temp[1].strip()
- if len(resignup.findall(title)) > 0:
- temp = title.split(':')
- actual_registered = temp[1].strip()
- if len(reemail.findall(title)) > 0:
- temp = title.split(':')
- actual_email = temp[1].strip()
- printProfile(actual_nick, actual_merits, actual_posts, actual_position, actual_registered, actual_lastlogin, actual_email)
- if actual_position != 'Legendary' and actual_position != 'Hero Member':
- next_position = getNextRank(actual_position)
- print 'Next Position:', next_position
- print 'Missing:', getMissingRequisites(actual_merits, actual_posts, next_position)
- if actual_position == 'Hero Member':
- next_position = getNextRank(actual_position)
- print 'Calculate luck'
- calculateLuck(actual_posts)
- print 'Missing:', getMissingRequisites(actual_merits, actual_posts, next_position)
- except Exception as e: print(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement