Advertisement
Guest User

Untitled

a guest
Oct 20th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import csv
  2. import urllib.request
  3. import pymysql.cursors
  4. connection = pymysql.connect(host='localhost',
  5. user='',
  6. password='',
  7. db='mydb',
  8. charset='utf8',
  9. cursorclass=pymysql.cursors.DictCursor)
  10. try:
  11. url = 'https://api.iextrading.com/1.0/stock/market/collection/sector?
  12. collectionName=Health%20Care&format=csv'
  13. response = urllib.request.urlopen(url)
  14. csv_data = csv.reader(response)
  15. for row in csv_data:
  16.  
  17. cursor.execute('INSERT INTO Financials (names,
  18. classes, mark )'
  19. 'VALUES("%s", "%s", "%s")',
  20. row)
  21. finally:
  22. connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement