-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjournal.py
More file actions
65 lines (47 loc) · 1.94 KB
/
Copy pathjournal.py
File metadata and controls
65 lines (47 loc) · 1.94 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
from .nbenvironment import NbEnvironment
import pandas as pd
import os
import logging
class Journal:
def __init__(self,debug=False):
try:
self.env = NbEnvironment()
except S3Error as e:
print(f"ERROR: Likely cause: File is not in a course folder.")
raise e
except Exception as e:
print(e)
raise e
@property
def properties(self):
return self.env.properties
def __get_path(self, netid = None):
if netid == None: netid = self.env.netid
return f"journal/{netid}.csv"
def init(self, netid = None):
tmp = "_tmp.csv"
journal_path = self.__get_path(netid)
logging.debug(f"CMD: init_journal netid={netid}, journal_path={journal_path}")
dataframe = pd.DataFrame( { 'Date' : [], 'Hours' : [], 'Comments' : [] } )
dataframe.to_csv(tmp,index=False)
response = self.env.mc.put(self.env.bucket,tmp,journal_path,)
os.remove(tmp)
logging.debug("DONE: init_journal")
return dataframe
def load(self, netid = None):
journal_path = self.__get_path(netid)
logging.debug(f"CMD: load_journal netid={netid}, journal_path={journal_path}")
#try:
dataframe = pd.read_csv(self.env.mc.get(self.env.bucket, journal_path))
#except: # ugh, bad coding here....
#dataframe = self.init(netid)
#pass
return dataframe
def save(self, dataframe, netid = None):
tmp = "_tmp.csv"
journal_path = self.__get_path(netid)
logging.debug(f"CMD: save_journal bucket={self.env.bucket} netid={netid}, journal_path={journal_path}")
dataframe.to_csv(tmp,index=False)
result = self.env.mc.fput(self.env.bucket,tmp,journal_path)
os.remove(tmp)
return result