forked from TimVdWalle/github-profile-updater
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
139 lines (110 loc) · 3.63 KB
/
start.py
File metadata and controls
139 lines (110 loc) · 3.63 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
################################################################
#
# INCLUDES / REQUIRES
#
################################################################
import os
from dotenv import load_dotenv
from datetime import date, datetime
import requests, json
from github import Github
# https://openweathermap.org/weather-conditions
# PyGithub
# OpenWeatherMap
################################################################
#
# CONFIG
#
################################################################
load_dotenv()
GITHUB_ACCESS_TOKEN = os.getenv('GITHUB_ACCESS_TOKEN')
OPEN_WEATHER_API_KEY = os.getenv('OPEN_WEATHER_API_KEY')
base_url = "http://api.openweathermap.org/data/2.5/weather?"
city_name = "Bruges"
################################################################
#
# INIT
#
################################################################
print("github profile updater")
g = Github(GITHUB_ACCESS_TOKEN)
################################################################
#
# FUNCTIONS
#
################################################################
def updateGitBio(bio):
print("updating bio in github profile:")
print(bio)
g.get_user().edit(bio=bio)
def fetch_weather():
complete_url = base_url + "appid=" + OPEN_WEATHER_API_KEY + "&q=" + city_name
print(complete_url)
# get method of requests module
# return response object
response = requests.get(complete_url)
# json method of response object
# convert json format data into
# python format data
x = response.json()
# Now x contains list of nested dictionaries
# Check the value of "cod" key is equal to
# "404", means city is found otherwise,
# city is not found
if x["cod"] != "404":
weather = x["weather"]
weather_id = weather[0]["id"]
weather_main = weather[0]["main"]
windspeed = x["wind"]["speed"]
# weather_description = weather[0]["description"]
# print(weather_id)
# print(weather_main)
# print(weather_description)
print("windspeed = ", windspeed)
return mapDescription(weather_id, weather_main, windspeed)
else:
print(" City Not Found ")
return "not snowing"
def mapDescription(id, main, windspeed):
if (main == "Mist"):
return "misty"
if (main == "Fog"):
return "foggy"
if (id == 202) or (id == 211) or (id == 212) or (id == 221) or (id == 232):
return "storming a lot"
if (id == 200) or (id == 201) or (id == 210) or (id == 230) or (id == 231):
return "storming"
if (main == "Drizzle"):
return "drizzling"
if (id == 500) or (id == 501) or (id == 520):
return "raining"
if (id == 502) or (id == 503) or (id == 504) or (id == 511) or (id == 521) or (id == 522) or (id == 531):
return "raining a lot"
if (id == 602) or (id == 621) or (id == 622):
return "snowing heavy"
if (id == 600) or (id == 601) or (id == 613) or (id == 615) or (id == 620):
return "snowing"
if (windspeed > 14):
return "storming"
if (main == "Clear"):
return "clear sky"
if (main == "Clouds"):
return "cloudy"
################################################################
#
# MAIN
#
################################################################
# add datetime to output for easier logging
now = datetime.now()
print("now =", now)
# fetching data weekday
weekday = date.today().strftime('%A (%d %B)')
bio1 = "Today is " + weekday
print(bio1)
# fetching data weather
weather = fetch_weather()
print(weather)
# updating bio
bio = bio1 + " and it is _" + weather + "_ here in Belgium."
updateGitBio(bio)