-
Notifications
You must be signed in to change notification settings - Fork 0
/
dailycloud.py
75 lines (50 loc) · 2.09 KB
/
dailycloud.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
#!/usr/bin/env python
"""
Daily clouds
"""
import datetime
import logging
import subprocess
import os
import json
import random
import pytz
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
TIME_ZONE = pytz.timezone('Europe/Rome')
#RANDOM_FONTS = ["Chelsea+Market"]
def load_google_fonts():
with open("google-fonts-list.json") as f:
fonts = json.load(f)
f = [x["family"] for x in fonts if x["category"] != 'handwriting']
return f
def main():
RANDOM_FONTS = load_google_fonts()
today = datetime.datetime.now(TIME_ZONE)
today_prefix = today.strftime("%Y%m%d-%H")
logger.info(' ... Creating cloud for ... % s' % today_prefix )
if not os.path.isdir(today_prefix):
os.mkdir(today_prefix)
today_feeds = os.path.join(today_prefix, "%s.txt" % today_prefix )
today_frequencies = os.path.join(today_prefix, "%s.freq.txt" % today_prefix )
today_cloud = os.path.join(today_prefix, "%s.image.png" % today_prefix )
today_config = os.path.join(today_prefix, "%s.config.json" % today_prefix )
if not os.path.isfile(today_feeds):
subprocess.check_call(["python", "feedsreader.py", "feeds.txt", today_feeds])
if not os.path.isfile(today_frequencies):
subprocess.check_call(["python", "cloud_maker.py", today_feeds, today_frequencies, "--frequencies-only", "--min-len=2"])
if not os.path.isfile(today_config):
with open("prova.config.json", "rt") as f:
base_config = json.load(f)
base_hue = random.randint(0, 360)
base_config["--color-func-params"] = "{\"base_hue\":%d, \"vibrance\":20}" % base_hue
#RANDOM FONT
base_config["--google-font"] = random.choice(RANDOM_FONTS)
with open(today_config, "wt") as fw:
base_config = json.dump(base_config, fw, indent=4)
cloud_args = ["python", "cloud_maker.py", today_frequencies, today_cloud, "--from-frequencies",
"--loadconfig", today_config]
subprocess.check_call(cloud_args)
logger.info(' ... Cloud done for ... % s' % today )
if __name__ == '__main__':
main()