Created
July 15, 2015 15:44
-
-
Save taddeimania/3b33a13add27775cd9f6 to your computer and use it in GitHub Desktop.
Python API Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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