[PYTHON] Bulk posting to Qiita: Team using Qiita API

Motivation

The group I belong to suddenly decided to introduce Qiita: team, "I want to move the Tip and know-how files that were originally shared in text to the Qiita Team." And that. .. .. I decided to try it first.

→ "You can always see the text via the web" → "Tag and manage easily" → "You can skip mentions within the team and have them read." I came up with something that looks good. .. .. I implemented batch posting with Qiita API.

The stumbled part

I started implementing it with a light feeling, but I ran into some problems.

  1. Bug with duplicate array of "tags"
  2. Unified text file encoding to utf-8
  3. Add tags for each directory

1. Array of'tags'

According to the Qiita API (http://qiita.com/docs/api#14) You can put name and version in the input tags.

before.json


{
    "title": "test",
    "body": "This is a test posting.",
    "tags": {
        "name": "tips"
    },
    "team_url_name": "ourteam"
}

I used to feel that. .. ..

after.json


{
    "title": "test",
    "body": "This is a test posting.",
    "tags": [
        {
            "name": "tips"
        }
    ],
    "team_url_name": "ourteam"
}

I was able to do this. This is a rudimentary mistake.

2. Unified text file encoding to utf-8

Even if I try to convert shift-jis to utf-8 on Mac, I noticed that there are several text files that cannot be read for some reason. When I open it with cotEditor. .. .. Windows DOS?

When I looked it up, it seemed to be the character code cp932. In the code implemented in Python, it seemed to be recognized separately from shift-jis.

3. Add tags for each directory

When posting a text file in any directory I decided to put that directory name in the tag. However, I don't know how to get a character string efficiently.

file_name, ext = os.path.splitext(file)
tag_line = files[len(path)+1:]
tag_list = tag_line.split('/')

Separate the file name and extension Cut the character string below path with'/' While implementing, "Oh, I wonder if there is a smarter way." I was coding with that in mind. (For the time being, I was able to get the character string as a tag as an array without any problem by this method.)

After mounting

If you think about it carefully, you can only edit the account you posted, so Later, I manually changed it to "co-editing", Tohoho.

When I contacted Mr. Qiita about this matter, It seems that it is supported by Qiita API v2 under development. I'm looking forward to it.

sample

https://github.com/tkshnkmr/qiita_api

Recommended Posts

Bulk posting to Qiita: Team using Qiita API
How to get article data using Qiita API
Try to delete tweets in bulk using Twitter API
How to display Map using Google Map API (Android)
Procedure to use TeamGant's WEB API (using python)
Easy to create API server using go-json-rest module
Recent ranking creation using Qiita API with Python
Try using ChatWork API and Qiita API in Python
Try posting to Qiita for the first time
[Rails] How to get location information using Geolocation API
[First API] Try to get Qiita articles with Python
Pre-processing to build seq2seq model using keras Functional API
Push notifications from Python to Android using Google's API
Try to make RESTful API with MVC using Flask 1.0.2
Post to your account using the API on Twitter
How to analyze with Google Colaboratory using Kaggle API
I tried to search videos using Youtube Data API (beginner)
How to reset password via API using Django rest framework
Challenge to generate Yahoo! News headlines using only COTOHA API
Qiita API Python wrapper for batch processing to grab Qiita posts
Try to determine food photos using Google Cloud Vision API
Tweet Now Playing to Twitter using the Spotify API. [Python]
Output product information to csv using Rakuten product search API [Python]