In [1]:
import requests
import pprint
In [2]:
with open('data/temp/qiita_access_token.txt') as f:
qiita_access_token = f.read().strip()
In [3]:
headers = {'Authorization': 'Bearer {}'.format(qiita_access_token)}
In [4]:
url_items = 'https://qiita.com/api/v2/items'
In [5]:
item_data = {
'title': 'テスト記事',
'body': 'テスト',
'private': True,
'tags': [{'name': 'test'}],
'coediting': False,
'gist': False,
'tweet': False
}
In [6]:
r_post = requests.post(url_items, headers=headers, json=item_data)
In [7]:
print(r_post.status_code)
In [8]:
pprint.pprint(r_post.json())
In [9]:
item_id = r_post.json()['id']
print(item_id)
In [10]:
r_get = requests.get(url_items + '/' + item_id, headers=headers)
In [11]:
print(r_get.status_code)
In [12]:
pprint.pprint(r_get.json())
In [13]:
item_data_updated = item_data.copy()
item_data_updated['title'] = 'テスト記事更新'
print(item_data_updated)
In [14]:
r_patch = requests.patch(url_items + '/' + item_id, headers=headers, json=item_data_updated)
In [15]:
print(r_patch.status_code)
In [16]:
pprint.pprint(r_patch.json())
In [17]:
r_delete = requests.delete(url_items + '/' + item_id, headers=headers)
In [18]:
print(r_delete.status_code)
In [19]:
url_tag = 'https://qiita.com/api/v2/tags/{}/following'
In [20]:
tag = 'python'
In [21]:
r_put = requests.put(url_tag.format(tag), headers=headers)
In [22]:
print(r_put.status_code)
In [23]:
r_delete_tag = requests.delete(url_tag.format(tag), headers=headers)
In [24]:
print(r_delete_tag.status_code)