-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_always.py
37 lines (25 loc) · 891 Bytes
/
run_always.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
# coding: utf-8
import scraper
import os
import time
import datetime
def git_add_commit_push(date, filename):
cmd_git_add = 'git add {filename}'.format(filename = filename)
cmd_git_commit = 'git commit -m "{date}"'.format(date = date)
cmd_git_push = 'git push -u origin master'
os.system(cmd_git_add)
os.system(cmd_git_commit)
os.system(cmd_git_push)
# scrape at predefined time, once a day
while True:
if time.strftime('%H:%M') == '23:30':
while True:
scraper.job()
# git add commit push
strdate = datetime.datetime.now().strftime('%Y-%m-%d')
dirname = datetime.datetime.now().strftime('%Y/%m')
filename = dirname + '/' + '{date}.md'.format(date = strdate)
git_add_commit_push(strdate, filename)
time.sleep(24 * 60 * 60)
else:
time.sleep(60)