python将记录写入Redis到适当的数据结构中

时间:2019-01-09 08:21:03

标签: python redis

我是python开发的新手,我有一个任务是将记录写入Redis并转换为适当的数据结构(字段:代码,名称,打开,高,低,关闭) 这是我的代码,用于从Web下载zip文件并提取读取的csv。现在我需要将记录写入Redis到适当的数据结构中(字段:代码,名称,打开,高,低,关闭)

import urllib
    import requests
    import zipfile
    import csv
    url = 'https://www.bseindia.com/download/BhavCopy/Equity/EQ080119_CSV.ZIP'
    #download file from request library
    r = requests.get(url)
    with open("code3.zip", "wb") as code:
        code.write(r.content)
    #extract the zip file  
    with zipfile.ZipFile("code3.zip","r") as zip_ref:
        zip_ref.extractall()
    # read csv file
    with open('EQ080119.CSV', 'r') as csvFile:
        reader = csv.reader(csvFile)
        for row in reader:
            print(row)

这是可变行的输出

['SC_CODE', 'SC_NAME', 'SC_GROUP', 'SC_TYPE', 'OPEN', 'HIGH', 'LOW', 'CLOSE', 'LAST', 'PREVCLOSE', 'NO_TRADES', 'NO_OF_SHRS', 'NET_TURNOV', 'TDCLOINDI']
['500002', 'ABB LTD.    ', 'A ', 'Q', '1300.05', '1309.00', '1294.00', '1297.00', '1295.05', '1299.85', '397', '8061', '10491069.00', '']
['500003', 'AEGIS LOGIS ', 'A ', 'Q', '209.10', '219.00', '204.25', '208.90', '208.90', '208.10', '111', '2999', '630550.00', '']

示例redis代码::

import redis
conn = redis.Redis('localhost')
conn.hmset("pythonDict", {"Location": "Ahmedabad"})
conn.hgetall("pythonDict")
output:  {b'Location': b'Ahmedabad'}

将记录写入Redis到适当的数据结构中(字段:代码,名称,打开,高,低,关闭)? 有人请帮助我...

0 个答案:

没有答案