In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to call the API interface to query the belonging place of mobile phone numbers". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Taking the interface of the converged data platform as an example, this paper explains how to obtain the phone number from the mysql database, query the home place and insert it into the database.
The code example is as follows:
#! / usr/bin/python#-*-coding: utf-8-*-import json, urllib, sys, pymysqlfrom urllib import urlencode, urlopenreload (sys) sys.setdefaultencoding ('utf8') # call API The result is a 2D dictionary def getPageCode (url, params): params = urlencode (params) f = urllib.urlopen (url, params) content = f.read () res = json.loads (content) return res # print ('Error code:% s'%res ["resultcode"]) # returns data processing for api interface. Def resTest (resdata): if resdata ["resultcode"] = = "200": # return valid result return resdata ["result"] else: # define error dictionary Resdata ["resultcode"] returns Error code Errorinfo = {'province':'Error code',' city':resdata ["resultcode"]} return Errorinfo # processing dictionary as a list of units def dictDate (data): province = data ["province"] city = data ["city"] res.append ((phoneNum, province, city)) # treats provinces and municipalities as one element: Liaoning, Huludao res1,res2 Res3 = res [0] [0], res [0] [1], res [0] [2] symbol =', 'resz = [(res1,res2+symbol+res3)] # print (' list res is:% s'%resz) return resz # connection database dblink = pymysql.connect (host = "10.10.10.31", user = "abc", password = "123456", database = "test" Charset = "utf8") # query data def select (db): cursor = db.cursor () cursor.execute ("select phoneNum from test.userinfo") # cursor.execute ("select phoneNum from test.userinfo order by id") ") # get a single piece of data using the fetchone () method. Fetchall () get all rows data= cursor.fetchall () # print data return data # insert data def install (db, data): cursor = db.cursor () sql =" update `test`.`userinfo` set location=%s where phoneNum =% s "# data= (first% s Second% s) data = (data [0] [1], data [0] [0]) cursor.execute (sql, data) db.commit () if _ _ name__ = "_ _ main__": url = "http://apis.juhe.cn/mobile/get" for phoneNum in select (dblink): phoneNum = phoneNum [0] params = {" phone ": phoneNum," key ":" 0ea8e44e4612fb794c29asdfde48hg " "dtype": "json",} res = [] # call getPageCode API ResTest processing data resdate = resTest ((getPageCode (url, params)) # is processed into a list of cell groups through the function dictDate, [('12676512732, u'\ u6d52\ u6c5f,\ u6e19\ u5dde')] resUlt = dictDate (resdate) install (dblink, resUlt) dblink.close () "how to call the API API to query the attribution of mobile phone numbers" is introduced here. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.