首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用python脚本将豆秆队列数据发送到Mssql

使用python脚本将豆秆队列数据发送到Mssql
EN

Stack Overflow用户
提问于 2020-02-07 08:18:26
回答 1查看 282关注 0票数 0

伙计们,我正在开发一个离线的ALPR解决方案。

到目前为止,我已经使用了运行在Ubuntu上的OpenAlpr软件。通过使用在StackOverlFlow上找到的python脚本,我能够读取ALPR的豆茎队列数据(板块号和元数据),但我需要将这些数据从豆茎队列发送到mssql数据库。有人知道如何将豆茎队列数据或JSON数据导出到数据库吗?下面的代码是针对本地主机的,如何修改它以自动将数据发布到mssql数据库?豆茎队列中的数据是JSON格式的key=value。

读写csv是我的新增功能,以查看它是否可以将json数据保存为localdisk上的csv。

代码语言:javascript
复制
import beanstalkc
import json
from pprint import pprint

beanstalk = beanstalkc.Connection(host='localhost', port=11300)
TUBE_NAME='alprd'
text_file = open('output.csv', 'w')

# For diagnostics, print out a list of all the tubes available in Beanstalk.
print beanstalk.tubes()

# For diagnostics, print the number of items on the current alprd queue.
try:
    pprint(beanstalk.stats_tube(TUBE_NAME))
except beanstalkc.CommandFailed:
    print "Tube doesn't exist"

# Watch the "alprd" tube; this is where the plate data is.
beanstalk.watch(TUBE_NAME)


while True:

    # Wait for a second to get a job. If there is a job, process it and delete it from the queue.
    # If not, return to sleep.
    job = beanstalk.reserve(timeout=5000)
    if job is None:
        print "No plates yet"
    else:
        plates_info = json.loads(job.body)
    # Do something with this data (e.g., match a list, open a gate, etc.).
    # if 'data_type' not in plates_info:
        # print "This shouldn't be here... all OpenALPR data should have a data_type"
    # if plates_info['data_type'] == 'alpr_results':
        # print "Found an individual plate result!"
    if plates_info['data_type'] == 'alpr_group':
        print "Found a group result!"
        print '\tBest plate: {} ({:.2f}% confidence)'.format(
            plates_info['candidates'][0]['plate'], 
            plates_info['candidates'][0]['confidence'])
        make_model = plates_info['vehicle']['make_model'][0]['name']
        print '\tVehicle information: {} {} {}'.format(
            plates_info['vehicle']['year'][0]['name'],
            plates_info['vehicle']['color'][0]['name'],
            ' '.join([word.capitalize() for word in make_model.split('_')]))
    elif plates_info['data_type'] == 'heartbeat':
        print "Received a heartbeat"
        text_file.write('Best plate')
    # Delete the job from the queue when it is processed.

job.delete()
text_file.close()
EN

回答 1

Stack Overflow用户

发布于 2020-08-18 21:48:09

AFAIK没有办法直接从beanstalkd导出数据。

  • 您所拥有的是有意义的,即将数据从管道中流到平面文件中,或者直接执行对DB的插入,因为IOPS beanstalkd是可以生成的,它可能仍然是一个合理的解决方案(取决于您期望的性能)

也试着问https://groups.google.com/forum/#!forum/beanstalk-talk

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60109510

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档