#encoding=gbk
import sys
import MySQLdb
import datetime
import time
dict = {"0":"0-0","1" : "0-500","2" : "500-700","3" : "700-900","4" : "900-1200",
"5" : "1200-1600","6" : "1600-2000","7" : "2000-2500","8" : "2500-3000",
"9" : "3000-3500","10" : "3500-4000","11" : "4000-5000","12" : "5000-7000",
"13" : "7000-10000","14" : "10000-14999","15" : "15000-19999",
"16" : "20000-29999","17" : "30000-49999",
"18" : "50000-100000","19" : "100000-100000",}
city=["鍚堣偉","鑺滄箹","铓屽煚","鍏畨","瀹夊簡",
"娣崡","椹瀺灞?,"娣寳","閾滈櫟","榛勫北",
"婊佸窞","闃滈槼","瀹垮窞","浜沖窞","姹犲窞",
"瀹e煄"]
def getvalue(x):
list=dict[x].split('-') #['0', '500']
return list
#璁$畻鏃堕棿
starttime = datetime.datetime.now()
conn=MySQLdb.Connection('127.0.0.1','root','123456','job',charset='gbk')
cur=conn.cursor()
#寰幆杈撳嚭鎵€鏈夊煄甯?
for ci in city:
#鍘婚櫎绌烘暟鎹?& 闈㈣鏁版嵁 & 宸ヤ綔鍦扮偣涓虹┖鏁版嵁
count=cur.execute("SELECT etjobsalary FROM demo_jobs_store\
WHERE etjoblocation_str LIKE '%%%s%%'"%ci)
conn.commit()
print "鎬昏褰曪細%s" %count
#鎵ц妫€鏌ョ粨鏋?
cur.scroll(0,mode='absolute')
results=cur.fetchall()
fields=cur.description
low=0
high=0
i=0
for ics in range(0,len(results)):
a=int(getvalue(results[ics-1][0])[0])
b=int(getvalue(results[ics-1][0])[1])
if a<100000 and b<100000:
low+=a
high+=b
print "%s鐨勫伐璧勬槸锛?%ci
print int((low/count)*0.01)*100
print int((high/count)*0.01)*100
#鏃堕棿缁撴潫
endtime = datetime.datetime.now()
#杈撳嚭鏃堕棿
print (endtime - starttime).seconds
浠g爜瑙i噴锛?
1銆侀渶瑕佸畨瑁卪ysqldb for python鐨勬彃浠?
2銆佽娈典唬鐮佺殑涓昏浣滅敤鏄粠mysql鏁版嵁搴撲腑瀛楁鍙栧嚭鏁版嵁锛屽苟涓旀牴鎹瓧娈靛搴旂殑鍊兼潵鍙栧鈎鍧囧€?
鏁版嵁搴撴埅鍥撅細
缁撴灉杈撳嚭濡傚浘锛?
鎬葷粨锛?
1銆佽娈典唬鐮佺敤鍒頒簡澶氱缁撴瀯锛屼緥濡俵ist鍜宒ict绛夈€?
2銆佺敤鍒頒簡鍑芥暟銆?
3銆佺敤鍒頒簡mysql鐨勫驚鐜鐞嗐€?
4銆佺粺璁$▼搴忚繍琛屾椂闂淬€?
鏂囩珷鏉ヨ嚜涔愯亴缃?聽http://www.lezhi.com/