Advertisement
thongld

unicode tsv output

Jul 2nd, 2016
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. #Better solution with tsv data
  2. #Simpler, unicode support, google spreadsheet support
  3. import requests #http://docs.python-requests.org/en/master/
  4. def unicode_normalize(text):
  5.  return text.translate({ 0x2018:0x27, 0x2019:0x27, 0x201C:0x22, 0x201D:0x22, 0xa0:0x20 }).encode('utf-8')
  6.  
  7. #init full_GraphAPI_for_group_or_page_URL
  8. #...
  9.  
  10. feed_json = requests.get(full_GraphAPI_for_group_or_page_URL).json()
  11. tsv_row = []
  12. for item in feed_json["data"]:
  13.  tsv_row = [item["id"]] + [item["message"]] + [item["created_time"]] # + ... so on
  14.  print unicode_normalize("\t".join(tsv_row))
  15.  
  16. #Save to this_script.py then run "this_script.py >> data.tsv" from command line
  17. #Open data.tsv with notepad or sublime > Copy All then paste to Google Spreadsheet for better data manipulation and sharing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement