nanowrimojson

In [ ]:
nanowrimo json

building a restful api for returning json data from nanowrimo

 Use our WriteAPI to update your word count via app or plugin!

wcapi -- what is it?

This page outlines the API for accessing the word count information for NaNoWriMo. There are five major types of information you can retrieve:

    current individual wordcount
    individual wordcount history
    site wordcount
    site wordcount history
    regional wordcount
    regional wordcount history
    
With the api I want to specify in the URL what user I want to look up rather than in the python script. 

For example 
In [4]:
import requests
import xmltodict
import json
from flask import Flask, jsonify
from flask_restful import Resource, Api
#import flask
In [25]:
app = Flask(__name__)
api = Api(app)
In [5]:
xmltodict.parse
Out[5]:
<function xmltodict.parse>
In [6]:
wcurl = ('http://nanowrimo.org/wordcount_api')
In [ ]:
 
In [7]:
#requind = requests.get('{}/wc/wcmckee'.format(wcurl))
In [8]:
#reqtxt = requind.text
In [9]:
#xmord = xmltodict.parse(reqtxt)
In [10]:
#json.dumps(xmord['wc'])
Out[10]:
'{"uname": "wcmckee", "user_wordcount": "0", "uid": "1996657", "winner": "false"}'
In [14]:
#reqwchis = requests.get('http://nanowrimo.org/wordcount_api/wchistory/wcmckee')
In [15]:
#wchistxt = reqwchis.text
In [18]:
#wchispar = xmltodict.parse(wchistxt)
In [22]:
#ordwcis = wchispar['wchistory']
In [26]:
class HelloWorld(Resource):
    def get(self):
        reqwchis = requests.get('http://nanowrimo.org/wordcount_api/wchistory/wcmckee')        
        wchistxt = reqwchis.text
        wchispar = xmltodict.parse(wchistxt)
        ordwcis = wchispar['wchistory']
        return jsonify(ordwcis)
In [ ]:
api.add_resource(HelloWorld, '/')
In [ ]:
if __name__ == '__main__':
    app.run(debug=True)
In [2]:
#reqthis = requests.get('{}/wcmhistory/wcmckee'.format(wcurl))
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-220ced7b9aeb> in <module>()
----> 1 reqthis = requests.get('{}/wcmhistory/wcmckee'.format(wcurl))

NameError: name 'wcurl' is not defined
In [3]:
#reqthis.text
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-e3d39e12920f> in <module>()
----> 1 reqthis.text

NameError: name 'reqthis' is not defined
In [ ]:
#/wchistory/ jezra 
In [24]:
#requind
Out[24]:
<Response [200]>
In [ ]:
 
In [ ]:
 

Comments

Comments powered by Disqus