ERPNext.com Frappe Cloud Support Partners Foundation Frappe School

How to create read csv file data and upload that data to erpnext doctype

import csv
from frappeclient import FrappeClient

longitude = 2
latitude = 2
country = 2
total = 2

client = FrappeClient(“https://grynn-demo-v13r.frappe.cloud/","e439cbde4675a4a”, “6d04d4b78c7c810”)

def sync():
print(“logging in…”)
#client = FrappeClient(“https://grynn-demo-v13r.frappe.cloud/","e439cbde4675a4a”, “6d04d4b78c7c810”)
with open(“test.csv”, “rU”) as testfile:
reader = csv.reader(testfile, dialect=‘excel’)
for row in reader:
if row[0]==“Timestamp”:
continue

		print("finding " + row[country])
		name = client.get_value("check",{"name": row[country]})

		if name:
			doc = client.get_doc(name["name"])
		else:
			doc = {"doctype":"check"}

		doc["longitude"] = row[longitude]
		doc["latitude"] = row[latitude]
		doc["country"] = row[country]
		doc["total"] = row[total]

if name==“main”:
sync()