forked from Stepheny755/ClanStatsBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
173 lines (146 loc) · 5.26 KB
/
data.py
File metadata and controls
173 lines (146 loc) · 5.26 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import json,csv,os
from util import Util
tdir = "Data/testdata"
adir = "Data"
wdir = "Data/wowsnumbers"
class Data():
name = ''
def __init__(self): #,inp):
#self.name = inp
pass
# INIT
# READ WRITE APPEND FUNCTIONS
def testread(self,filename):
rdarr = []
with open(os.path.join(tdir,filename).strip(),'r') as r:
rdarr = list(csv.reader(r,delimiter=','))
return rdarr
def testwrite(self,relativepath,filename,output):
temppath = os.path.join(tdir,relativepath).strip()
if not os.path.exists(temppath):
os.makedirs(temppath)
with open(os.path.join(temppath,filename).strip(),'w+') as w:
out = csv.writer(w)
out.writerows(output)
def read(self,relativepath,filename):
rdarr = []
temppath = os.path.join(adir,relativepath).strip()
with open(os.path.join(temppath,filename).strip(),'r') as r:
rdarr = list(csv.reader(r,delimiter=','))
return rdarr
def write(self,relativepath,filename,output):
temppath = os.path.join(adir,relativepath).strip()
if not os.path.exists(temppath):
os.makedirs(temppath)
with open(os.path.join(temppath,filename).strip(),'w+') as w:
out = csv.writer(w)
out.writerows(output)
def readtxt(self,relativepath,filename):
rdarr = []
temppath = os.path.join(adir,relativepath).strip()
with open(os.path.join(temppath,filename).strip(),'r') as r:
return r.read()
def writetxt(self,relativepath,filename,output):
temppath = os.path.join(adir,relativepath).strip()
if not os.path.exists(temppath):
os.makedirs(temppath)
with open(os.path.join(temppath,filename).strip(),'w+') as w:
w.write(str(output))
def append(self,relativepath,filename,output):
temppath = os.path.join(adir,relativepath).strip()
if not os.path.exists(temppath):
os.makedirs(temppath)
with open(os.path.join(temppath,filename).strip(),'a+') as a:
a.write(output+"\n")
# READ WRITE APPEND FUNCTIONS
# CLAN RELATED FUNCTIONS
def addToClanlist(self,name):
templist = self.read('','ClanList')
for clanname in templist:
if(clanname[0]==name):
print(clanname[0])
return
self.append('','ClanList',name)
def trackClan(self,clanname,data):
temppath = os.path.join(adir,clanname).strip()
if not os.path.exists(temppath):
os.makedirs(temppath)
u = Util()
time = u.getGMTTime()
self.write(clanname,str(time)+'.csv',data)
pass
# CLAN RELATED FUNCTIONS
# WOWSNUMBERS FUNCTIONS
def getWMostRecent(self):
#TODO: Find value (either ID or name of ship) in expected value csv, and return associated dmg,frag, and WR data
lst = []
for file in os.listdir(wdir):
if file.endswith('.csv'):
lst.append(file)
return max(lst)
def getExpectedData(self):
filename = self.getWMostRecent()
file = self.read('wowsnumbers',filename)
#print(file)
return file
# WOWSNUMBERS FUNCTIONS
# SHIP RELATED FUNCTIONS
def getShipID(self,name):
data = self.getExpectedData()
for ship in data:
if(ship[1]==name):
return int(ship[0].strip())
return None
def getShipStats(self,sID):
data = self.getExpectedData()
for ship in data:
if(int(ship[0])==sID and len(ship)>2):
#print(ship[1])
return ship[len(ship)-3],ship[len(ship)-2],ship[len(ship)-1]
# SHIP RELATED FUNCTIONS
# SAVED STATS FUNCTIONS
def getMostRecent(self,path):
lst = []
rpath = os.path.join(adir,path).strip()
for file in os.listdir(rpath):
if file.endswith('.txt') or file.endswith('.csv'):
lst.append(file)
if lst:
t = max(lst)
else:
return None
return t
def getLatestbeforeDate(self,path,time):
lst = []
rpath = os.path.join(adir,path).strip()
for file in os.listdir(rpath):
if file.endswith('.csv'):
if(int(file[:-4])<time):
lst.append(file)
if lst:
t = max(lst)
else:
return None
return t
if(__name__=="__main__"):
d = Data()
#d.testwrite('test','test1.csv',[['jacky','cool'],['jacky','smart']])
#c = d.testread('Book1.csv')
#c = d.read("",'ClanList')
#print(c)
#for i in c:
#for z in i:
#print(z)
#print("done")
#print(d.getWMostRecent())
#print(d.getExpectedData())
#print(d.trackClan('MIA',[['mod','shitter'],['ddak','absolut trash'],['warlord','legend']]))
#d.addToClanlist('asdf')
#print(d.read('','ClanList'))
#print(d.getShipID("Dresden"))
#print(d.getShipStats(d.getShipID("Alaska")))'
ut = Util()
print(d.read("MIA-E/Modulatus",d.getMostRecent("MIA-E/Modulatus/")))
print(d.read("MIA-E/Modulatus",d.getLatestbeforeDate("MIA-E/Modulatus",ut.countWeekSec())))
#data = [["wr",50.532],["avgdmg",203021],['kills',2],['pr',2410]]
#d.testwrite("MIA/test",str(ut.getGMTTime())+'.csv',data)