Created
January 30, 2018 19:11
-
-
Save anonymous/19e2ad86e8ffe850c4396f265f80d0c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lxml.html | |
import tabun_api as api | |
import getpass | |
i = 1 | |
c = 0 | |
vote = 0 | |
topics = {} | |
TOTALWORDS = 0 | |
TOTALVOTES = 0 | |
s = input("Введите ваш ник:") | |
f = open('%s.txt' % s,'w', encoding='utf-8') | |
pas = getpass.getpass("Введите пароль. Чтобы посчитать комментарии только на внешке, нажмите Enter:") | |
n = int(input("Не выводить топики, где Вы оставили n или меньше комментов, где n=")) | |
user = api.User(login = s, passwd = pas) | |
try: | |
html = user.urlread("/profile/{0}/created/comments/page{1}/".format(s, i)).decode('utf-8') | |
except api.TabunError as exc: | |
if exc.code != 500: raise | |
html = exc.exc.read().decode('utf-8') | |
page = lxml.html.fromstring(html) | |
t = page.xpath("//*[@id='content']/div[3]/ul[2]/li[6]/a/@href") | |
if t: | |
t=str(t[0]) | |
t = int(t[(t.index('/page'))+5:len(t)-1]) # пока-что я не осиливаю модуль re :( | |
t/=2 | |
else: | |
t=int(3) | |
while True: | |
print("Смотрим на страницу номер {0}, насчитано слов: {1}, плюсов: {2}, осталось примерно {3} секунд ".format(i, TOTALWORDS, TOTALVOTES, t)) | |
t-=0.5 | |
try: | |
html = user.urlread("/profile/{0}/created/comments/page{1}/".format(s, i)).decode('utf-8') | |
except api.TabunError as exc: | |
if exc.code != 500: raise | |
html = exc.exc.read().decode('utf-8') | |
page = lxml.html.fromstring(html) | |
comments = page.xpath('//*[@id="content"]/div[2]/section') | |
for comment in comments: | |
topic = (comment.xpath('div[2]/ul/li[last()]/a[2]/text()')) | |
if topic: #исключение для пустого топика | |
topic = str(topic[0]) | |
c = str(comment.xpath('div[1]/div/text()')).count(' ') + 1 | |
vote = (int(comment.xpath('div[2]/ul[1]/li[3]/span/text()')[0])) | |
if topic not in topics: | |
topics[topic]=[0, 0, 0] | |
topics[topic][0]+=1 # сколько всего комментов в этом топике | |
topics[topic][1]+=c | |
topics[topic][2]+=vote | |
TOTALWORDS+=c | |
TOTALVOTES+=vote | |
i+=1 | |
if comments == []: | |
break | |
stats = sorted(topics.items(), key = lambda l: l[1], reverse = True) | |
for stat in stats: | |
if n >= stat[1][0]: | |
break | |
a = str("%s за " % s + str(stat[1][0]) + " коммент(ов) написал " + str(stat[1][1]) + " слов(а) в топике " + "'" + str(stat[0]) + "'" + ", получив за это " + str(stat[1][2]) + '\n') | |
f.write(a) | |
a = str("Всего слов: " + str(TOTALWORDS) + ", всего плюсов в Ваших комментах: " + str(TOTALVOTES) + '\n') | |
f.write(a) | |
print("На рабочем столе создан файл с Вашим ником") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment