Personal Records 2 retrieval billing

Source: Internet
Author: User

#!/usr/bin/python

Import Pycurl

Import OS

Import MySQLdb

Import Cstringio

Import Simplejson

Import Redis


def fts_get_appname (HOST,USER,PORT,DB,PASSWD):

Conn=mysqldb.connect (Host=str (host), User=user,passwd=passwd,port=int (port), db=db)

Cur=conn.cursor (Cursorclass=mysqldb.cursors.dictcursor)

Cur.execute (' Select Appname,accesskey from KeyPair where extsrvstatus like '%ab% '; ')

Result=cur.fetchall ()

return result


def CURL_SOLR (Acceskey):

url = ' Http://****/solr/collection1/select?q=userid: ' +acceskey+ ' &wt=json&indent=true '

Buf=cstringio.stringio ()

C=pycurl. Curl ()

C.setopt (C.url,url)

C.setopt (C.writefunction,buf.write)

C.perform ()

Return Buf.getvalue ()

Buf.close ()

def set_redis_billing (R,acceskey,app_sum_data):

R.rpush (' List_an ', "1\t%s\tfts\t%s\t0"% (acceskey,app_sum_data))


if __name__ = = ' __main__ ':

app_dict={}

mysql_dict = {' IP ': ' * * * ', ' user ': ' * * * ', ' port ':* * *, ' db ': ' * * * ', ' passwd ': ' * * * '}

Host = mysql_dict[' IP ']

user = mysql_dict[' user ']

Port = mysql_dict[' Port ']

db = mysql_dict[' db ']

passwd = mysql_dict[' passwd ']

Fts_appname = Fts_get_appname (HOST,USER,PORT,DB,PASSWD)

Pool = Redis. Strictredis (host= ' * * * *, port=***)

For I in Fts_appname:

AccessKey = i[' AccessKey ']

AppName = i[' appname ']

App_dict[appname] = {}

#app_dict [appname] = AccessKey

Solr_url_result = CURL_SOLR (AccessKey)

Dict_solr_url_result = Simplejson.loads (Solr_url_result)

App_sum_data = dict_solr_url_result[' response ' [' Numfound ']

Print App_sum_data

App_dict[appname][accesskey]=str (App_sum_data)

If App_sum_data! = 0:

Set_redis_billing (Pool,accesskey,app_sum_data)

Print App_dict


This article from "Expect volume synchronization data" blog, declined reprint!

Personal Records 2 retrieval billing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.