-
Notifications
You must be signed in to change notification settings - Fork 9
/
import_export_file.py
69 lines (55 loc) · 1.65 KB
/
import_export_file.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
import json
import pickle
import glob
import os
import pandas as pd
import filesystem_changes as fc
import string_manipulation as sm
# create the export pickle file
def make_pickle():
details = f'{fc.find_last_created_folder()}game details.json'
lineups = glob.glob(os.path.join(fc.find_last_created_folder(), '*lineup*'))
actions = f'{fc.find_last_created_folder()}actions.csv'
with open(details) as f:
details = json.load(f)
f.close()
with open(f'{fc.downloads_path()}/fileExport.sports', 'wb') as fp:
pickle.dump(details, fp)
for lineup in lineups:
df = pd.read_csv(lineup)
pickle.dump(df.to_dict('records'), fp)
df = pd.read_csv(actions)
pickle.dump(df.to_dict('records'), fp)
fp.close()
# this will at some point allow to import pickle files to the program
def read_pickle(path):
lines = []
with (open(path, 'rb')) as openfile:
while True:
try:
lines.append(pickle.load(openfile))
except EOFError:
break
details = []
actions = []
lineups = []
# keeping only details
for det in lines[0]:
details.append([det, lines[0][det]])
lines.pop(0)
# keeping only names, family actions,actions, timestamps
for act in lines[2]:
a_list = []
for a in act:
a_list.append(act[a])
actions.append(a_list)
lines.pop(2)
# we'll see
for line in lines:
for l1 in line:
l3 = []
for l2 in l1:
l3.append(l1[l2])
lineups.append(l3)
# return arrays
return details, lineups, actions