forked from kenshin17/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autofill.py
executable file
·46 lines (43 loc) · 1.55 KB
/
autofill.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
#!/usr/local/bin/python2.7
# -*- coding: utf-8 -*-
import json
import gspread
import smtplib
import datetime
from oauth2client.client import SignedJwtAssertionCredentials
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
now = datetime.datetime.now()
today = now.strftime('%m/%d/%Y')
# authorize google
json_key = json.load(open('/home/path/k/token.json'))
scope = ['https://spreadsheets.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'].encode(), scope)
gc = gspread.authorize(credentials)
# access google sheets
worksheet = gc.open("Tien An Nhom").sheet1
# tim cac o co stt la 10
k = worksheet.findall("10")
# kiem tra cac o cuoi cung cua cac dot tien an, luu vao mang
moneys =[]
for i in k:
money = worksheet.acell("H"+str(i.row)).value
if money:
moneys.append(worksheet.acell("H"+str(i.row)))
# lay dia chi hang o cuoi cung cua dot tien an
row = moneys[-1].row
count = row+1
for i in xrange(row,row+10):
if (worksheet.acell("B"+str(count)).value):
count +=1
else:
if (now.weekday() < 5):
worksheet.update_acell(("B"+str(count)), str(today))
worksheet.update_acell(("C"+str(count)), '1')
worksheet.update_acell(("D"+str(count)), '1')
worksheet.update_acell(("E"+str(count)), "1")
worksheet.update_acell(("F"+str(count)), "1")
worksheet.update_acell(("G"+str(count)), "4")
worksheet.update_acell(("H"+str(count)), "40")
break
print "OK r"