Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from lxml import html
- import sys
- import re
- import requests
- 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': 'xx',
- }
- 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
- 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)
- return 'Merits:', missing_merits, 'Activity:', missing_activity
- if __name__ == '__main__':
- uid = sys.argv[1]
- print 'UID', uid
- remerit = re.compile(r"Merit")
- reactivity = re.compile(r"Activity")
- reposition = re.compile(r"Position")
- actual_merits = 0
- actual_posts = 0
- actual_position = ''
- tree = getProfile(uid)
- try:
- datas = tree.xpath('//td[@class="windowbg"]/table/tr')
- for data in datas:
- title = data.text_content().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()
- print 'Merits:', actual_merits
- print 'Activity:', actual_posts
- print 'Position:', actual_position
- if actual_position != 'Legendary':
- next_position = getNextRank(actual_position)
- print 'Next Position:', next_position
- print 'Missing:', getMissingRequisites(actual_merits, actual_posts, next_position)
- except:
- print 'any error happenD'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement