Skip to content

Instantly share code, notes, and snippets.

@taddeimania
Created July 15, 2015 15:44
Show Gist options
  • Save taddeimania/3b33a13add27775cd9f6 to your computer and use it in GitHub Desktop.
Save taddeimania/3b33a13add27775cd9f6 to your computer and use it in GitHub Desktop.
Python API Client
import requests
API_HOST = "http://localhost:8000/api3/"
AUTH_TOKEN = "ebea682e0ff80c453fb179b042c22d11d8e6179f"
def get_movie_list():
return [movie['title'] for movie in requests.get(API_HOST + "movie/").json()]
def create_movie(title, funny):
requests.post(API_HOST + "movie/create/",
data={"title": title, "funny": funny},
headers={"Authorization": "Token " + AUTH_TOKEN})
input_value = 1
while input_value:
print("[1] Get all Movies")
print("[2] Create a movie")
input_value = int(input("Choice? "))
if input_value == 1:
for movie in get_movie_list():
print(movie)
print("\n")
elif input_value == 2:
title = input("Title? ")
funny = input("Funny? ")
create_movie(title, bool(funny))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment