Created
December 27, 2018 13:36
-
-
Save ikait/499cd14bbfe9e90e77964e9eb4f2446c to your computer and use it in GitHub Desktop.
This file contains 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
#coding: utf-8 | |
import json | |
from flask import jsonify | |
import requests | |
APPLE_DEVICE_LIST_URL = "https://raw.githubusercontent.com/pbakondy/ios-device-list/master/devices.json" | |
apple_device_list = [] | |
def apple_devices(request): | |
"""Return apple device info. | |
""" | |
global apple_device_list | |
if not apple_device_list: | |
apple_device_list = requests.get(APPLE_DEVICE_LIST_URL).json() | |
model = request.args.get('model') | |
if model: | |
devices = [] | |
for device in apple_device_list: | |
if model in device["model"]: | |
devices.append(device) | |
return jsonify(devices) | |
name = request.args.get('name') | |
if name: | |
devices = [] | |
for device in apple_device_list: | |
if name in device["name"]: | |
devices.append(device) | |
return jsonify(device) | |
return jsonify(apple_device_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment