Advertisement
Guest User

jojo

a guest
Apr 8th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. import requests
  2. import json
  3. #from prettytable import PrettyTable
  4. #import mysql.connector
  5. import pymysql
  6. import time
  7. conn = pymysql.connect(user='', password='',
  8.                                   host='amazonaws.com',
  9.                                   database='')
  10. cursor = conn.cursor()
  11. startTime = time.time()
  12. while True:
  13.     UR: = "https://api.coinmarketcap.com/v1/ticker/"
  14.     request = requests.get(URL)
  15.     data = request.json()
  16.     for x in data:
  17.         name = x['name']
  18.         symbol = x['symbol']
  19.         price_usd_data = x['price_usd']
  20.         rank = int(x['rank'])
  21.         query2 = "INSERT INTO price_usd (name, symbol, rank, 5_min) VALUES (%s, %s, %s, %s); "  
  22.         print(query2)
  23.        # time.sleep(5)
  24.         cursor.execute(query2, (name, symbol, rank, price_usd_data))
  25.         query3 = "INSERT INTO price_usd (30_min) VALUES (%s) WHERE (symbol=%s); "
  26.         time.sleep(2)
  27.         cursor.execute(query3 (price_usd_data), (symbol))
  28.         conn.commit()
  29.     cursor.close()
  30.     conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement