This repository was archived by the owner on Oct 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch_notes_reader.py
More file actions
73 lines (64 loc) · 2.09 KB
/
patch_notes_reader.py
File metadata and controls
73 lines (64 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
file: patch_notes_reader.py
language: python3
author: Shantanav Saurav << ss9415@g.rit.edu >>
purpose: Read patch notes from given patch
"""
import requests, re, patch_url_scraper, sys, read_file
from bs4 import BeautifulSoup
def get_notes_info(url: str) -> None:
"""
Get info from one particular set of patch notes
----Pre Conditions:
link -> str: Patch to be read
----Post Conditions:
return -> None
"""
try:
notes = requests.get(url)
except Exception:
print("There was an error establishing a connection to the provided URL.")
soup = BeautifulSoup(notes.text, 'html.parser')
article_title = soup.find('h1', {'class' : 'article-title'}).text.strip()
blockquote = soup.find('blockquote')
summary = str()
try:
summary = blockquote.text.split("\n")
summary = " ".join([i.strip() for i in summary])
summary = summary.strip()
except Exception:
pass
video = soup.find('iframe', allowfullscreen=True)
if video is not None:
video = "https://" + video['src'].split("//")[1]
else:
video = ''
image = ''
try:
image = soup.find('div', {'class' : 'file-image'}).find('a')['href']
except Exception:
pass
return url, article_title, summary, video, image
def main() -> None:
"""
Main Function
----Pre/Post:
N/A
"""
urls = read_file.read_file("urls.txt")
try:
get_notes_info(urls[sys.argv[1].lower()])
except KeyError:
print("That patch does not exist on the na.leagueoflegends.com website.")
most_recent = str()
with open("urls.txt") as f:
most_recent = f.readline().strip().split(": ")[0]
print("The oldest patch available is Patch 3.04, and the newest patch is Patch " + most_recent)
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: patch_notes_reader.py <patch number>")
else:
if re.search(r"^[\d]{1,2}\.[\d]{1,2}[\w]?([-][tT][fF][tT])?$", sys.argv[1]):
main()
else:
print("Please enter a valid patch number.")