Advertisement
Guest User

Untitled

a guest
May 29th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. rom time import mktime
  2. import mysql.connector
  3. import datetime
  4.  
  5. from dateutil.relativedelta import relativedelta
  6. db = mysql.connector.connect(user='user_dataengineering', password='dataengineering',
  7. host='ruudlinssen.com',
  8. database='dataengineering')
  9.  
  10. cursor = db.cursor()
  11. nodes = []
  12. edges = []
  13. amount = []
  14. purdata = []
  15. hhdata = []
  16. years = ["1974_final", "1975_final", "1976_final", "1977_final", "1978_final", "1979_final", "1980_final", "1981_final", "1982_final",
  17. "1983_final", "1984_final", "1985_final", "1986_final", "1987_final", "1988_final", "1989_final",
  18. "1990_final", "1991_final", "1992_final", "1993_final", "1994_final", "1995_final", "1996_final",
  19. "1997_final", "1998_final", "1999_final", "2000_final"]
  20. i = 0
  21. for table in years:
  22. #print("""SELECT hhno, gor, stmth, styr FROM %s WHERE TRUE ORDER BY styr, stmth, gor, hhno""" % (table))
  23. cursor.execute("""SELECT hhno, gor, stmth, styr FROM %s WHERE 1 ORDER BY styr""" % (table))
  24. hhdata.extend(cursor.fetchall())
  25. for row in hhdata:
  26. if not any(p['hhno'] == row[0] for p in nodes):
  27. nodes.append({
  28. 'id': len(nodes),
  29. 'node label': "Household",
  30. 'hhno': row[0],
  31. 'region': row[1],
  32. })
  33. print(datetime.datetime.now())
  34. # Output to files
  35. f = open('household_nodes.csv', 'w')
  36.  
  37. for node in nodes:
  38. to_write = [
  39. node['id'],
  40. 'Node Label',
  41. node['Node Label']
  42. ]
  43.  
  44. for key, value in node.iteritems():
  45. if key not in ['id', 'Node Label']:
  46. to_write.append(key)
  47. to_write.append(value)
  48.  
  49. f.write(', '.join([str(i) for i in to_write]))
  50. f.write('\n')
  51.  
  52. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement