-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathofflinedata.py
More file actions
38 lines (31 loc) · 1.09 KB
/
offlinedata.py
File metadata and controls
38 lines (31 loc) · 1.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
'''
offlinedata.py
TMWRK
Edited By:
Robert Schaffer
Class for writing and reading last known weather data in case
there is no internet connection for API calls
'''
from datetime import datetime
import pickle
class offlineData:
def __init__(self):
self.numLocations = 0
self.locationData = []
self.datetime
def addLocationData(self, data):
self.locationData.append(data)
self.numLocations += 1
def writeOfflineData(self):
self.datetime = datetime.now()
with open('offline_data.pkl', 'wb') as outp:
pickle.dump(self.datetime, outp, pickle.HIGHEST_PROTOCOL)
pickle.dump(self.numLocations, outp, pickle.HIGHEST_PROTOCOL)
for data in self.locationData:
pickle.dump(data, outp, pickle.HIGHEST_PROTOCOL)
def readOfflineData(self):
with open('offline_data.pkl', 'rb') as inp:
self.datetime = pickle.load(inp)
self.numLocations = pickle.load(inp)
for num in range (0, self.numLocations):
self.addLocationData(pickle.load(inp))