Skip to content

Instantly share code, notes, and snippets.

@mcotton
Last active July 11, 2017 16:10
Show Gist options
  • Save mcotton/c544ccb17febb5774874c76ead267613 to your computer and use it in GitHub Desktop.
Save mcotton/c544ccb17febb5774874c76ead267613 to your computer and use it in GitHub Desktop.
Ugly way to create projects from csv
import csv
with open('Titan-1.csv', 'rU') as csvfile:
filereader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in filereader:
new_p = Project(title="%s - %s" % (site.name, row[0]),
company=comp.key,
company_name=comp.name,
wind_farm=site.name,
site = site.key,
location="%s, %s" % (row[1], row[2]),
is_EOW=False,
is_turbine=True,
show_live_report=True,
show_links_in_live_report=True,
has_image=True,
has_checklist=False,
status="1_initialized")
new_p.put()
@mcotton
Copy link
Author

mcotton commented Jul 11, 2017

Similar problem, updating location of existing projects

with open('balko.csv', 'rU') as csvfile:
   ...:     filereader = csv.reader(csvfile, delimiter=',', quotechar='"')
   ...:     for row in filereader:
   ...:         proj = Project.query(ndb.AND(Project.title==row[0], Project.company==co.key)).get()
   ...:         if proj is None:
   ...:             print "Couldn't find %s" % row[0]
   ...:             continue
   ...:         else:
   ...:             proj.location = row[1]
   ...:             print "Updating %s to location %s" % (row[0], row[1])
   ...:             proj.put()
   ...:             

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment