Skip to content

Instantly share code, notes, and snippets.

@ayanctech
Created March 31, 2020 05:43
Show Gist options
  • Save ayanctech/1c27e79d5b4b5ad3fbc56b78d65c8a89 to your computer and use it in GitHub Desktop.
Save ayanctech/1c27e79d5b4b5ad3fbc56b78d65c8a89 to your computer and use it in GitHub Desktop.
Steps to Execute the code-
import requests
from itertools import groupby
name = 'Ayan Chowdhury'
email = '[email protected]'
file = open("work2.txt", "r")
lst = file.readlines()
file.close()
URL = "https://docs.google.com/forms/d/e/1FAIpQLSfvEXoydIjEYUVKqD2xn0d7Q-UgkkSSpYQ1rHBVJYpLqZGC5g/formResponse"
dv = (list(g) for _, g in groupby(lst, key='\n'.__ne__))
res = [a + b for a, b in zip(dv, dv)]
dates = []
wfh_type = []
duration = []
time = []
reason = []
result = []
for i in res:
dates.append(i[0])
wfh_type.append(i[1])
duration.append(i[2])
time.append(i[3])
reason.append(i[4])
result.append("".join(i[5:-1]))
#Demo format
val={
"emailAddress": email,
"entry.298863725": name,
"entry.1818038140_year": "2020",
"entry.1818038140_month": "03",
"entry.1818038140_day": "20",
"entry.444390987": "Full Day",
"entry.1842582045": "duration",
"entry.448533363": "timeslot",
"entry.973326035": "reason",
"entry.1514654442": "list_of_works"
}
l = len(res)
print("Length",l)
for i in range(l):
val={}
ds = dates[i].split("-")
val[ "emailAddress"] = email,
val[ "entry.298863725"] = name,
val[ "entry.1818038140_year"] = "2020",
val[ "entry.1818038140_month"] = ds[ 0],
val[ "entry.1818038140_day"] = ds[ 1],
val[ "entry.444390987"] = "Full Day",
val[ "entry.1842582045"] = duration[ i],
val[ "entry.448533363"] = time[ i],
val[ "entry.973326035"] = reason[ i],
val[ "entry.1514654442"] = result[i]
print(val)
resp = requests.post(URL, val)
print(resp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment