Try using ChatWork API and Qiita API in Python

Recently I've noticed that JetBrains products are free for students. So, I wanted to touch Python, so I took PyCharm. Well, there is also a community edition.

So, I tried using chat work and Qiita's API, so it's just a memo.

(Maybe it's a little rough)

ChatWork API

chatwork.py


#coding: UTF-8
print "Content-Type: application/json"

import pycurl
import urllib

c = pycurl.Curl()
api_token = 'Your API Key'
me = 'https://api.chatwork.com/v1/me'
status = 'https://api.chatwork.com/v1/my/status'
tasks = 'https://api.chatwork.com/v1/my/tasks'
room_message = 'https://api.chatwork.com/v1/rooms/{room_id}/messages'

# ===== GET =====
print "GET"
print "============="

c.setopt(pycurl.HTTPHEADER, ['X-ChatWorkToken:' + api_token])

print "-----I-----"
c.setopt(pycurl.URL, me)
c.perform()

print()
print "-----status-----"
c.setopt(pycurl.URL, status)
c.perform()

print()
print "-----task-----"
c.setopt(pycurl.URL, 'https://api.chatwork.com/v1/my/tasks')
c.perform()

print()

# ===== POST =====

option = {'body': 'Python ChatWork API Test'}
c.setopt(pycurl.URL, room_message)
c.setopt(pycurl.HTTPHEADER, ['X-ChatWorkToken:' + api_token])
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, urllib.urlencode(option))
c.perform()

#I don't plan to use the update, so I won't write it.

Qiita API

qiita.py


#coding: UTF-8
import pycurl
import urllib
import urllib2
import cookielib
import json

def get_user(username):
    """
Get the specified user information
    :param username:
    :return:
    """
    url = "https://qiita.com/api/v1/users/" + username
    c = pycurl.Curl()
    c.setopt(pycurl.URL, url)
    c.perform()

def get_my_stock(token):
    """
Get your own stock posts
    :return:
    """
    url = "https://qiita.com/api/v1/stocks" + "?token=" + token
    c = pycurl.Curl()
    c.setopt(pycurl.URL, url)
    c.perform()

# http is urllib2.HTTPHandler(debuglevel=1)
opener = urllib2.build_opener(urllib2.HTTPSHandler(debuglevel=1),
                          urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
urllib2.install_opener(opener)

#Authentication
login_post = {'url_name': 'Your User Name', 'password': 'Your Password'}
params = urllib.urlencode(login_post)
request = urllib2.Request('https://qiita.com/api/v1/auth', params)
request_read = urllib2.urlopen(request)
token = json.loads(request_read.read())
token = token['token']

#Get your own stock posts
print get_my_stock(token)

#Get your information
print get_user('UserName')

What's good about a Python framework? .. .. I touched Pyramid for a moment.

Recommended Posts

Try using ChatWork API and Qiita API in Python
Try using the Wunderlist API in Python
Try using the Kraken API in Python
Try using the BitFlyer Ligntning API in Python
Try using the DropBox Core API in Python
Try using Pleasant's API (python / FastAPI)
Try using LevelDB in Python (plyvel)
Try using Python argparse's action API
Try to make it using GUI and PyQt in Python
Predict gender from name using Gender API and Pykakasi in Python
Mouse operation using Windows API in Python
Notes using cChardet and python3-chardet in Python 3.3.1.
Try logging in to qiita with Python
Tweet using the Twitter API in Python
Get Youtube data in Python using Youtube Data API
Quickly try Microsoft's Face API in Python
Try hitting the YouTube API in Python
Build and try an OpenCV & Python environment in minutes using Docker
Get image URL using Flickr API in Python
Evernote API in Python
Send messages to Skype and Chatwork in Python
Let's judge emotions using Emotion API in Python
Development and deployment of REST API in Python using Falcon Web Framework
Try gRPC in Python
Recent ranking creation using Qiita API with Python
Try using tensorflow ① Build python environment and introduce tensorflow
C API in Python 3
Try 9 slices in Python
Try using Tweepy [Python2.7]
[First API] Try to get Qiita articles with Python
Upload JPG file using Google Drive API in Python
Try creating a compressed file using Python and zlib
Get LEAD data using Marketo's REST API in Python
Send and receive Gmail via the Gmail API using Python
PHP and Python samples that hit the ChatWork API
Try to delete tweets in bulk using Twitter API
OpenVINO using Inference Engine Python API in PC environment
Read and write NFC tags in python using PaSoRi
Speech transcription procedure using Python and Google Cloud Speech API
Using the National Diet Library Search API in Python
[Python] Try using Tkinter's canvas
Try using Kubernetes Client -Python-
Try using the Twitter API
Try using the Twitter API
Stack and Queue in Python
Try using the PeeringDB 2.0 API
Try implementing Yubaba in Python 3
Blender Python API in Houdini (Python 3)
Unittest and CI in Python
Translate using googletrans in Python
Using Python mode in Processing
Try hitting the Twitter API quickly and easily with Python
Collect tweets using tweepy in Python and save them in MongoDB
Try building a neural network in Python without using a library
Graph time series data in Python using pandas and matplotlib
Specification generation and code generation in REST API development (Python edition)
Try running a function written in Python using Fn Project
I made a Chatbot using LINE Messaging API and Python
Aggregate and analyze product prices using Rakuten Product Search API [Python]
Try using Janus gateway's Admin API
Try using Spyder included in Anaconda