Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions api_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import datetime
from urllib.parse import quote
from urllib.request import urlopen
from json import loads
from itertools import groupby


def main():
url = 'https://ru.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&rvlimit=500&titles=%D0%93%D1%80%D0%B0%D0%B4%D1%81%D0%BA%D0%B8%D0%B9,_%D0%90%D0%BB%D0%B5%D0%BA%D1%81%D0%B0%D0%BD%D0%B4%D1%80_%D0%91%D0%BE%D1%80%D0%B8%D1%81%D0%BE%D0%B2%D0%B8%D1%87'
stats = get_revision_statistics(url,'183903')
print_stats_in_file(stats, 'stats.txt')
# 2021-11-28 153 - Всплеск изменений был вызван новостями о болезни и последующей смерти Александра Градского

url = f'https://ru.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&rvlimit=500&titles={quote("Бельмондо,_Жан-Поль")}'
stats = get_revision_statistics(url,'192203')
print_stats_in_file(stats, 'stats1.txt')
# 2021-09-06 58 - Здесь самый крупный всплеск правок за последнее время
# (на эту-же дату приходиться и смерть актёра).
# Но это не значит, что такая метрика точна, т.к. всплеск
# активности может быть вызван другими событиями


def get_revision_statistics(url, pageid):
data = loads(urlopen(url).read().decode('utf8'))
revisions = sorted(data['query']['pages'][pageid]['revisions'], key=get_date, reverse=True)
groups = groupby(revisions, get_date)
result = {}
for k, g in groups:
result[k] = list(g)
return result


def print_stats_in_file(result, filename):
with open(filename, 'w', encoding='utf8') as f:
for k in result:
print(k, len(result[k]), file=f)


def get_date(x):
return datetime.datetime.strptime(x['timestamp'], '%Y-%m-%dT%H:%M:%SZ').date()


if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions news.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions news2.json

Large diffs are not rendered by default.

149 changes: 149 additions & 0 deletions stats.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
2021-12-04 4
2021-12-03 12
2021-12-02 23
2021-12-01 11
2021-11-30 6
2021-11-29 16
2021-11-28 153
2021-11-27 5
2021-11-26 9
2021-11-24 1
2021-11-16 1
2021-11-15 2
2021-11-14 1
2021-11-11 1
2021-10-17 2
2021-10-10 3
2021-09-25 2
2021-09-24 1
2021-09-17 2
2021-09-01 1
2021-08-27 2
2021-08-23 3
2021-08-18 1
2021-07-16 2
2021-06-08 1
2021-06-03 1
2021-04-28 1
2021-03-25 3
2021-02-06 2
2021-01-31 1
2020-12-29 1
2020-12-28 1
2020-11-27 2
2020-10-30 2
2020-10-29 2
2020-10-24 4
2020-10-21 3
2020-10-15 3
2020-10-06 1
2020-09-29 1
2020-07-31 2
2020-07-30 1
2020-07-08 2
2020-06-05 2
2020-05-18 2
2020-04-12 2
2020-04-11 1
2020-04-10 2
2020-03-24 2
2020-02-18 3
2020-01-16 1
2019-12-04 4
2019-11-23 6
2019-11-19 1
2019-11-15 1
2019-11-11 2
2019-11-10 1
2019-11-09 1
2019-11-08 2
2019-11-06 4
2019-11-03 3
2019-10-30 7
2019-10-19 1
2019-08-14 1
2019-08-07 1
2019-07-26 1
2019-05-23 2
2019-05-20 1
2019-04-02 2
2019-02-27 2
2019-02-26 1
2019-02-18 1
2019-02-15 1
2019-01-27 1
2019-01-21 4
2019-01-12 4
2018-12-23 5
2018-12-22 7
2018-12-14 2
2018-11-09 2
2018-11-03 1
2018-11-01 4
2018-10-26 1
2018-09-19 5
2018-09-15 1
2018-09-07 3
2018-08-15 1
2018-08-11 4
2018-08-05 3
2018-07-23 2
2018-06-30 4
2018-06-15 1
2018-05-16 1
2018-04-06 1
2018-04-04 1
2018-04-02 1
2018-02-18 1
2018-01-13 1
2018-01-04 3
2018-01-03 2
2017-12-30 1
2017-12-20 2
2017-12-19 2
2017-12-02 1
2017-11-27 4
2017-11-10 2
2017-11-08 1
2017-10-25 1
2017-10-09 1
2017-10-03 1
2017-09-29 1
2017-09-23 2
2017-09-15 1
2017-09-14 2
2017-09-08 1
2017-08-21 2
2017-08-14 4
2017-08-02 1
2017-06-30 1
2017-06-29 1
2017-06-25 3
2017-06-04 3
2017-05-28 1
2017-05-16 1
2017-05-14 2
2017-05-06 2
2017-04-18 1
2017-03-26 1
2017-03-09 1
2017-03-01 1
2017-02-23 1
2017-02-22 4
2017-02-18 1
2017-02-10 1
2017-01-27 1
2016-12-04 2
2016-11-27 2
2016-11-26 1
2016-10-29 1
2016-10-20 1
2016-10-06 1
2016-09-16 1
2016-09-02 1
2016-08-31 2
2016-08-30 1
2016-08-25 1
2016-08-23 1
2016-07-23 1
2016-07-16 3
Loading