Skip to content

Instantly share code, notes, and snippets.

@ejetzer
Created November 9, 2015 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejetzer/f29099adf8e008b3a3b8 to your computer and use it in GitHub Desktop.
Save ejetzer/f29099adf8e008b3a3b8 to your computer and use it in GitHub Desktop.
NNWM Wordcount.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys, requests, hashlib
if sys.version_info.major == 2: input = raw_input
# You can get you key from http://nanowrimo.org/api/wordcount
KEY = '8996ghhhftdgn87j'
USER = 'ejetzer'
wordcount = input('How many words?')
hashed = hashlib.sha1(KEY + USER + wordcount).hexdigest()
print(hashed)
content = 'hash={}&name={}&wordcount={}'.format(hashed, USER, wordcount)
print(content)
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
response = requests.put('https://nanowrimo.org/api/wordcount', content, headers=headers)
if response.status_code != 200:
print('There has been a problem.')
print(response)
for i, v in response.headers.items():
print(i, ':', v)
print()
print(response.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment