daily pastebin goal
74%
SHARE
TWEET

get_brand_master.py

TDCustmerSupportJP Jul 31st, 2017 (edited) 72 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 bs4 import BeautifulSoup
  13. import urllib
  14. from urllib2 import Request, urlopen, URLError, HTTPError
  15. from pprint import pprint
  16.  
  17. def get_result(url):
  18.     fp = urlopen(url); contents = fp.read(); fp.close();
  19.     return contents
  20.  
  21. # params
  22. api_key = "XXXXXX" # https://webservice.recruit.co.jp/register/index.html よりAPI KEY を取得して下さい。
  23.  
  24. # url info
  25. base_url = "http://webservice.recruit.co.jp/carsensor/brand/v1/?key=%s&format=json"%(api_key)
  26.  
  27. ##### main #####
  28. res =  json.loads(get_result(base_url))
  29. main = res["results"]["brand"]
  30.  
  31. filename = "brand_master.csv"
  32. writecsv = csv.writer(file(filename, 'w'), lineterminator='\n')
  33. writecsv.writerow(["country", "country_code", "name", "code"])
  34.  
  35. for jsn in main:
  36.     country_name = jsn["country"]["name"]
  37.     country_code = jsn["country"]["code"]
  38.     name = jsn["name"]
  39.     code = jsn["code"]
  40.     writecsv.writerow([country_name.encode('utf-8'), country_code.encode('utf-8'), name.encode('utf-8'), code.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