[PYTHON] I stumbled on the Hatena Keyword API

I stumbled on the Hatena Keyword API. The script itself works fine, so I think it's okay if only Unicode processing works.

hatenaapi.py


#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
import xmlrpclib
import sys, codecs
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)

get_input = raw_input("prease keywords: ")


server = xmlrpclib.ServerProxy("http://d.hatena.ne.jp/xmlrpc")
res = server.hatena.getSimilarWord({"wordlist": get_input})
print res["wordlist"]

When I run it, it picks it up, but there is a problem with Unicode processing. Unicode appears as it is in the displayed character string.

Well, if you just pick up related keywords ... I realized that I was lacking in study, so I decided to write a memorandum.

*******************************************

For the time being, I thought that I could do something about Unicode escape, I saved it externally as txt and read it.

hatenaapi.py


#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
import xmlrpclib
import sys, codecs
sys.stdin  = codecs.getreader("utf-8")(sys.stdin)
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)

get_input = raw_input("prease keywords: ")

server = xmlrpclib.ServerProxy("http://d.hatena.ne.jp/xmlrpc")
res = server.hatena.getSimilarWord({"wordlist": get_input})


f = open("hatena.txt" , "aw")
lists = res["wordlist"]

for x in lists:
	f.write(str(x) + "\n")
	f.close


f = open("hatena.txt","rb")
data = f.read()
f.close()
print data.decode("unicode-escape")

Isn't it easier?

Recommended Posts

I stumbled on the Hatena Keyword API
Where I stumbled on SQLite3
I touched the Qiita API
I tried the Naro novel API 2
I tried the Naruro novel API
I tried using the checkio API
I tried using the COTOHA API (there is code on GitHub)
I stumbled upon installing sentencepiece on ubuntu
I tried to touch the COTOHA API
I tried using the BigQuery Storage API
I checked the library for using the Gracenote API
I tried using Remote API on GAE / J
I tried hitting the Qiita API from go
I stumbled on the character code when converting CSV to JSON in Python
I tried using the Google Cloud Vision API
I tried to touch the API of ebay
I ran the neural network on the actual FPGA
I tried LINE Message API (line-bot-sdk-python) on GAE
I tried playing with the calculator on tkinter
I did a little research on the class
I tried Python on Mac for the first time.
I tried running the app on the IoT platform "Rimotte"
Maybe I overestimated the impact of ShellShock on CGI
I tried python on heroku for the first time
What I did when I stumbled on a Django tutorial
Post to your account using the API on Twitter
I tried using the API of the salmon data project
I tried installing the Linux kernel on virtualbox + vagrant
I tried to notify the honeypot report on LINE
I moved the automatic summarization API "summpy" with python3.
I tried hitting the API with echonest's python client
I counted the grains
I tried tensorflow's new Object Detection API on macOS Sierra
I tried running PIFuHD on Windows for the time being
I installed the automatic machine learning library auto-sklearn on centos7
I tried saving the DRF API request history with django-request
I tried touching the multi-vendor router control API library NAPALM
I made a VGG16 model using TensorFlow (on the way)
Image Optimize on the server side using TinyPNG's Web API
[Python] I tried collecting data using the API of wikipedia
I tried the Google Cloud Vision API for the first time
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
I tried to launch ipython cluster to the minimum on AWS
I stumbled on TensorFlow (What is Out of GPU Memory)
I tried to get various information from the codeforces API
I made an original program guide using the NHK program guide API.
[For beginners] I tried using the Tensorflow Object Detection API