-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
85 lines (73 loc) · 2.76 KB
/
config.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
74
75
76
77
78
79
80
81
82
83
84
85
import pyfiglet
import yaml
from pathlib import Path
from os import linesep
from sys import platform
config_yaml = Path('config.yaml')
most_recent_conversations = []
def defaults():
pre_decrypt = False
if platform == 'darwin':
signal_path = Path('~/Library/Application Support/Signal').expanduser()
photos_path = Path('./images')
if not photos_path.exists():
photos_path.mkdir()
elif platform == 'linux': # ie. WSL
pre_decrypt = True
parts = Path.cwd().parts
userdir_parts = parts[0:parts.index('Users') + 2]
userdir = Path(*userdir_parts)
signal_path = userdir / 'AppData/Roaming/Signal'
photos_path = userdir / 'Pictures/iCloud Photos/Photos'
else:
raise NotImplementedError('Platform is not supported:', platform)
return {
'import_photos_from_messages': {
'any_with_my_reaction': [],
'in_conversation': {
'include': ['*'],
'exclude': []
}
},
'output_path': str(photos_path),
'x-advanced': {
'signal_path': str(signal_path),
'pre_decrypt': pre_decrypt,
'pre_copy': pre_decrypt,
'sqlcipher_bin': './sqlcipher/sqlcipher'
} ,
'last_run': 0
}
def load():
global config
if not config_yaml.exists():
config = defaults()
save()
print('This is a first run. Please check the generated "config.yaml", modify and press enter to continue (config will be reloaded).')
input()
load()
else:
with open(config_yaml) as f:
config = yaml.safe_load(f)
convo_filter = get('import_photos_from_messages.in_conversation')
if ('*' in convo_filter['include']) == ('*' in convo_filter['exclude']):
raise RuntimeError('Invalid conversation filters. Either one of "include" or "exclude" needs to contain the glob "*".')
def save():
with open(config_yaml, 'w') as f:
header = (linesep + pyfiglet.figlet_format('Configuration', font='smscript')).replace(linesep, linesep + '# ', 5)
f.write(header + linesep)
yaml.safe_dump(config, f, allow_unicode=True)
if most_recent_conversations:
f.write(linesep)
f.write('# For your exclusion/inclusion convenience:')
f.write(linesep)
f.write(f'# The {len(most_recent_conversations)} most recently active conversation names.')
f.write((linesep + '# - ').join([''] + most_recent_conversations))
def get(path):
handle = config
for key in path.split('.'):
handle = handle.get(key)
return handle
def conversation_list(conversations):
global most_recent_conversations
most_recent_conversations = conversations