forked from frappe/frappe-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
57 lines (45 loc) · 1.61 KB
/
example.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
# Example
# Import job applications from a CSV File (created via Google Forms) to "Job Application"
import csv
import asyncio
from frappeclient import FrappeClient
NAME = 2
EMAIL = 3
INTRODUCTION = 4
THOUGHTS_ON_COMPANY = 5
LIKES = 6
LINKS = 7
PHONE = 8
async def sync():
print("logging in...")
client = FrappeClient("https://xxx.frappecloud.com", "xxx", "xxx")
with open("jobs.csv", "r") as jobsfile:
reader = csv.reader(jobsfile, delimiter='\t')
for row in reader:
print(row)
if row[0] == "Timestamp":
continue
print("finding " + row[EMAIL])
name = await client.get_value("Job Applicant", "name", {"email_id": row[EMAIL]})
if name:
doc = await client.get_doc("Job Applicant", name["name"])
else:
doc = {"doctype": "Job Applicant"}
doc["applicant_name"] = row[NAME]
doc["email_id"] = row[EMAIL]
doc["introduction"] = row[INTRODUCTION]
doc["thoughts_on_company"] = row[THOUGHTS_ON_COMPANY]
doc["likes"] = row[LIKES]
doc["links"] = row[LINKS]
doc["phone_number"] = row[PHONE]
if doc.get("status") != "Rejected":
doc["status"] = "Open"
if name:
await client.update(doc)
print("Updated " + row[EMAIL])
else:
await client.insert(doc)
print("Inserted " + row[EMAIL])
if __name__ == "__main__":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(sync())