-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelperFunctions.py
More file actions
101 lines (86 loc) · 3.55 KB
/
HelperFunctions.py
File metadata and controls
101 lines (86 loc) · 3.55 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
import sys, subprocess, urllib.request, json, datetime
from oauth2client import file, client, tools
from darksky import forecast
from apiclient.discovery import build
from httplib2 import Http
from PyQt5.QtGui import QFont, QFontMetrics
#retrieves calendar events
def getCalendar():
# Setup the Calendar API
SCOPES = 'https://www.googleapis.com/auth/calendar.readonly'
store = file.Storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('calendar', 'v3', http=creds.authorize(Http()))
# Call the Calendar API
now = datetime.datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
print('Getting the upcoming 10 events')
events_result = service.events().list(calendarId='primary', timeMin=now,
maxResults=10, singleEvents=True,
orderBy='startTime').execute()
events = events_result.get('items', [])
return events
# if not events:
# print('No upcoming events found.')
# for event in events:
# start = event['start'].get('dateTime', event['start'].get('date'))
# print(start, event['summary'])
#retrieves weather from Dark Sky
def getWeather():
#DarkSky API key
key = 'c663651149db5b56479353e7968d6db7'
#retrieving local forecast
homeWeather = forecast(key, 35.1983, -111.651)
#extracting daily weather
currentTemp = str(homeWeather.temperature) + "°"
daily_data = homeWeather.daily[0]
highTemp = str(daily_data.temperatureMax) + "°"
lowTemp = str(daily_data.temperatureMin) + "°"
windSpeed = str(daily_data.windSpeed) + " mph"
windGust = str(daily_data.windGust) + " mph"
sunrise = datetime.datetime.fromtimestamp(daily_data.sunriseTime).strftime('%I:%M') + " AM"
sunset = datetime.datetime.fromtimestamp(daily_data.sunsetTime).strftime('%I:%M') + " PM"
precipChance = str(daily_data.precipProbability) + "%"
try:
precipType = daily_data.precipType
except:
precipType = -1
print('no precip type found')
#extracting weather alerts
try:
alerts = homeWeather.alerts[0]
alertTitle = alerts.title
alertStart = alerts.time
alertEnd = alerts.expires
except:
print('no alerts found')
alertTitle = -1
alertStart = -1
alertEnd = -1
#creating dailyWeather list
day = datetime.datetime.now()
dailyWeather = [currentTemp, highTemp, lowTemp, precipChance, precipType, windSpeed, windGust, sunrise, sunset]
#extracting weekly weather
weeklyWeather = []
for i in range(1, 7):
daily_data = homeWeather.daily[i]
weeklyWeather.append([daily_data.temperatureMax, daily_data.temperatureMin, daily_data.precipProbability])
day += datetime.timedelta(days=1)
return [dailyWeather, weeklyWeather]
#grabs primary screen dimensions from linux commands
def initDimensions():
cmd = ['xrandr']
cmd2 = ['grep', '*']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
p2 = subprocess.Popen(cmd2, stdin=p.stdout, stdout = subprocess.PIPE)
p.stdout.close()
resolution_string, junk = p2.communicate()
resolution = resolution_string.split()[0].decode('utf-8')
width, height = resolution.split('x')
width, height = int(width), int(height)
return width, height
def getStringDims(text, font):
metrics = QFontMetrics(font)
return metrics.boundingRect(text)