#!/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