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
58 changes: 58 additions & 0 deletions DZ_API.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import datetime
import itertools
from json import loads
from urllib.request import urlopen


# Градский %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
# page_id: 183903
# page_id: Жан-Поля Бельмондо: 192203
# Жан-Поль Бельмондо: %D0%91%D0%B5%D0%BB%D1%8C%D0%BC%D0%BE%D0%BD%D0%B4%D0%BE,_%D0%96%D0%B0%D0%BD-%D0%9F%D0%BE%D0%BB%D1%8C


def main():
Alex_Grad_page_title = '%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'
Jan_Pol_page_title = '%D0%91%D0%B5%D0%BB%D1%8C%D0%BC%D0%BE%D0%BD%D0%B4%D0%BE,_%D0%96%D0%B0%D0%BD-%D0%9F%D0%BE%D0%BB%D1%8C'
Alex_Grad_page_id = '183903'
Jan_Pol_page_id = '192203'

save_as_json(get_stat(Alex_Grad_page_id, Alex_Grad_page_title), 'StatAlexGrad.txt')
save_as_json(get_stat(Jan_Pol_page_id, Jan_Pol_page_title), 'StatJanPol.txt')


def get_stat(page_id, page_title):
data = read_wiki(page_id, page_title)
revisions = sorted(data, key=get_date, reverse=True)
groups_rev = itertools.groupby(revisions, get_date)
res = {}
for date, group in groups_rev:
res[date] = list(group)
return res


def read_wiki(page_id, page_title):
url = f'https://ru.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&rvlimit=500&titles={page_title}'
data = loads(urlopen(url).read().decode('utf8'))
return data['query']['pages'][page_id]['revisions']


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


def save_as_json(revisions, file_name):
with open(file_name, 'w', encoding='utf-8') as file:
for date in revisions:
file.write(f'{date} {len(revisions[date])}\n')


if __name__ == "__main__":
main()
#
#Всплеск правок звазян со смертью Александра Градского.
#Дата смерти Жан-Поля Бельмондо 6 сентября 2021, что совпадает со "всплеском"
#правок его странички. Но пользоваться такой метрикой,на мой взгляд, ошибочно,
#так как события другого характера могут вызывать больший всплекс активности правок.
#


48 changes: 48 additions & 0 deletions DZ_XML.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import json
import xml.etree.ElementTree as ET
from urllib.request import urlopen


def main():
items = read_lentaRU()
save_as_json(write_pd_and_title(items), 'new1.json')
save_as_json(write_all_in_item(items), 'new2.json')


def read_lentaRU():
data = urlopen('https://lenta.ru/rss').read().decode('utf8')
root = ET.fromstring(data)
return root.find('channel').findall('item')


def write_pd_and_title(items):
res = []
for item in items:
res.append(
{
"pubDate": item.find("pubDate").text,
"title": item.find("title").text
}
)
return res


def write_all_in_item(items):
res = []
for item in items:
res_dict = {}
for i in item.iter():
if i.tag != 'item':
res_dict[i.tag] = i.text
res.append(res_dict)
return res


def save_as_json(json_list, file_name):
with open(file_name, 'w', encoding='utf8') as jsonFile:
json.dump(json_list, jsonFile, ensure_ascii=False, indent=1)


if __name__ == "__main__":
main()

136 changes: 136 additions & 0 deletions StatAlexGrad.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
2021-12-23 1
2021-12-22 5
2021-12-21 4
2021-12-20 1
2021-12-17 1
2021-12-16 1
2021-12-15 3
2021-12-14 2
2021-12-11 1
2021-12-09 3
2021-12-08 2
2021-12-07 2
2021-12-06 5
2021-12-05 1
2021-12-04 10
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 2
Loading