daily pastebin goal
95%
SHARE
TWEET

get_large_area_master.py

TDCustmerSupportJP Jul 31st, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4.  
  5. import sys,os,re
  6. import time,datetime
  7. import json,msgpack,yaml,csv
  8. from pprint import pprint
  9. import argparse
  10. import dateutil.parser
  11.  
  12. from csv import DictWriter
  13. from bs4 import BeautifulSoup
  14. import urllib
  15. from urllib2 import Request, urlopen, URLError, HTTPError
  16. from pprint import pprint
  17.  
  18. parser = argparse.ArgumentParser(description='SOME COMMENT')
  19. # parser.add_argument('--type', dest='type', type=int, required=True, help= 'rank type: [02,10]')
  20. args = parser.parse_args()
  21.  
  22. def get_result(url):
  23.     fp = urlopen(url); contents = fp.read(); fp.close();
  24.     return contents
  25.  
  26. # params
  27. api_key = "XXXXXX" # https://webservice.recruit.co.jp/register/index.html よりAPI KEY を取得して下さい。
  28.  
  29. # url info
  30. base_url = "http://webservice.recruit.co.jp/carsensor/large_area/v1/?key=%s&format=json"%(api_key)
  31.  
  32. ##### main #####
  33. res =  json.loads(get_result(base_url))
  34. main = res["results"]["large_area"]
  35.  
  36. filename = "large_area_master.csv"
  37. writecsv = csv.writer(file(filename, 'w'), lineterminator='\n')
  38. writecsv.writerow(["code", "name"])
  39.  
  40.  
  41. for dic in main:
  42.     code = dic["code"]
  43.     name = dic["name"] 
  44.     writecsv.writerow([code.encode('utf-8'), name.encode('utf-8')])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top