Created
January 11, 2020 05:34
-
-
Save uenoku/6b4a868b48dab464c66890675a4191af to your computer and use it in GitHub Desktop.
sotsuron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gspread | |
from oauth2client.service_account import ServiceAccountCredentials | |
import sys | |
import time | |
import datetime | |
import subprocess | |
import argparse | |
scope = ['https://spreadsheets.google.com/feeds', | |
'https://www.googleapis.com/auth/drive'] | |
parser = argparse.ArgumentParser(description='Post wordcount to spreadsheets.') | |
parser.add_argument("--sleep", type=int, default=300, help='sleep time') | |
parser.add_argument("credentials_json", type=str, help='credentials.json') | |
parser.add_argument("gspread_key", type=str, help='spreadsheet id') | |
args = parser.parse_args() | |
credentials = ServiceAccountCredentials.from_json_keyfile_name(args.credentials_json, scope) | |
gc = gspread.authorize(credentials) | |
sh = gc.open_by_key(args.gspread_key) | |
wk = sh.get_worksheet(0) | |
deadline = datetime.datetime(year=2020, month=1, day=31) | |
while True: | |
dtn = datetime.datetime.now() | |
td = deadline - dtn | |
texc = subprocess.check_output(["texcount main.tex"], shell=True) | |
texc = texc.decode('utf-8').split("\n") | |
word = int(texc[2].split(" ")[-1]) | |
print([str(dtn), str(td), -td.seconds, word]) | |
wk.append_row([str(dtn), str(td), -td.seconds, word]) | |
time.sleep(args.sleep) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment