-
Notifications
You must be signed in to change notification settings - Fork 0
/
presidents.py
executable file
·99 lines (80 loc) · 2.71 KB
/
presidents.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python3
# Developer : Hamdy Abou El Anein
# hamdy.aea@protonmail.com
# Make changes to the json file only with pycharm and json viewer.
# The data can take time to be fully updated on the server-side. (raw json).
import json
import urllib.request
from easygui import *
import wget
import os
import sys
key = 0
def first():
global key
if key > (len(presid) - 1):
key = 0
filepath = "president.png"
if os.path.exists(filepath):
os.remove(filepath)
url = presid[key]["picture"]
filename = wget.download(url, out="president.png")
image = "president.png"
msg = (
(presid[key]["president"])
+ str("\n")
+ str("President number : ")
+ str(presid[key]["number"])
+ str("\n")
+ str("Political party : ")
+ str(presid[key]["party"])
+ str("\n")
+ str("Birth year : ")
+ str(presid[key]["birth_year"])
+ str(" Death year : ")
+ str(presid[key]["death_year"])
+ str("\n")
+ str("Took office : ")
+ str(presid[key]["took_office"])
+ str(" Left office : ")
+ str(presid[key]["left_office"])
+ str("\n")
+ str(presid[key]["history"])
)
if key < (len(presid) - 1):
choices = ["Next"]
else:
choices = ["Begin", "Quit"]
reply = buttonbox(msg, image=image, choices=choices)
if reply == "Next":
key = key + 1
first()
elif reply == "Begin":
key = 0
parser()
elif reply == "president.png":
key = key + 1
first()
else:
sys.exit(0)
def parser():
global presid
url = "https://raw.githubusercontent.com/hamdyaea/USA-Presidents-history/master/pictures/presidentseal.png"
filepath = "presseal.png"
if os.path.exists(filepath):
os.remove(filepath)
filename = wget.download(url, out="presseal.png")
image = "presseal.png"
msg = "Presidents of the United States\n\nThe purpose of the program is to introduce a little more the history of the presidents of the United States. The data will be changed when there is a change in the presidency of the United States.\n\nThe updated data is downloaded automatically.\n\nDeveloper : Hamdy Abou El Anein"
choices = ["Continue"]
reply = buttonbox(msg, image=image, choices=choices)
if reply == "Continue" or "presidenseal.png":
urlData = "https://raw.githubusercontent.com/hamdyaea/USA-Presidents-history/master/presidents.json"
webURL = urllib.request.urlopen(urlData)
data = webURL.read()
encoding = webURL.info().get_content_charset("utf-8")
presid = json.loads(data.decode(encoding))
else:
sys.exit(0)
first()
parser()