-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfs.py
73 lines (63 loc) · 1.74 KB
/
fs.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
70
71
72
73
import pickle
from os.path import join
from os import listdir
from os import path
import re
def checkWad():
if not path.exists('data.wad'):
open('data.wad', 'x')
with open('data.wad', 'wb') as f:
pickle.dump(wad(), f)
class wad:
def __init__(self, oldWad = {}):
self.bookLines = oldWad
self.ao3Remotes = []
def getFics():
with open("data.wad", "rb") as f:
x = f.read()
x = pickle.loads(x)
if x.ao3Remotes:
return x.ao3Remotes.copy()
else: return []
def addFic(fic):
x = None
with open("data.wad", "rb") as f:
x = f.read()
x = pickle.loads(x)
x.ao3Remotes = fic
with open("data.wad", "wb") as f:
x = pickle.dumps(x)
f.write(x)
def listBooks():
books = listdir("books")
return books
def getBook(fileName):
with open(join("books",fileName), "rt") as f:
v = f.read()
v = re.split(r' *[\.\?!][\'"\)\]]* *', v)
while '' in v:
v.remove('')
while '\n' in v:
v.remove('\n')
while '***' in v:
v.remove('***')
while '...' in v:
v.remove('...')
v = [item.strip() for item in v]
return v
def readLine(book):
with open("data.wad", "rb") as f:
x = f.read()
x = pickle.loads(x)
if book in x.bookLines:
return x.bookLines[book]
else: return 0
def setLine(book, line):
x = None
with open("data.wad", "rb") as f:
x = f.read()
x = pickle.loads(x)
x.bookLines[book] = line
with open("data.wad", "wb") as f:
x = pickle.dumps(x)
f.write(x)