Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Теплинский Артём АТ-20 #33

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions Result.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Александр Градский.
Самое большое количество правок было 2021-11-28 их 153, связанно с его смертью
![alt text](img/img_1.png)


Жан-Поль Бельмондо

Дата смерти 2021-09-06
![alt text](img/img.png)
Binary file added img/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/img_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from tasks_3_4 import *

from tasks_1_2 import *

if __name__ == '__main__':


task3()
1 change: 1 addition & 0 deletions result1.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions result2.json

Large diffs are not rendered by default.

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


def load_data():
data = urlopen('https://lenta.ru/rss').read().decode('utf8')
root = ET.fromstring(data)
return root

def task1(xml_root):
with open("result1.json", 'w', encoding='utf-8') as file:
result = []
for item in xml_root.iter('item'):
pubDate = item.find('pubDate').text
title = item.find('title').text
result.append({
'pubDate': pubDate,
'title': title
})
json.dump(result, file, ensure_ascii=False)


def task2(xml_root: ET.Element):
with open("result2.json", 'w', encoding='utf-8') as file:
result = []
for item in xml_root.iter('item'):
temp = {}
for element in item.iter():
if element.tag != 'item':
temp[element.tag] = element.text

result.append(temp)

json.dump(result, file, ensure_ascii=False)
33 changes: 33 additions & 0 deletions tasks_3_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import datetime
from itertools import groupby
from json import loads
from operator import itemgetter
from urllib.request import urlopen

def get_date(jsonObj):
return datetime.date.fromisoformat(jsonObj['timestamp'][0:jsonObj['timestamp'].find('T')])


def get_sorted_reviews(revisions):
result = {}
for key, items in groupby(revisions, key=get_date):
result[key] = sum(1 for _ in items)
return result


def task3():

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'
data = loads(urlopen(url).read().decode('utf8'))
revisions = data['query']['pages']['183903']['revisions']

for key, value in sorted(get_sorted_reviews(revisions).items(), key=itemgetter(1), reverse=True):
print(key, value)


def task4():
url = 'https://ru.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&rvlimit=500&titles=%D0%91%D0%B5%D0%BB%D1%8C%D0%BC%D0%BE%D0%BD%D0%B4%D0%BE,%20%D0%96%D0%B0%D0%BD-%D0%9F%D0%BE%D0%BB%D1%8C'
data = loads(urlopen(url).read().decode('utf8'))
revisions = data['query']['pages']['192203']['revisions']
key, val = sorted(get_sorted_reviews(revisions).items(), key=itemgetter(1), reverse=True)[0]
print(key, val)