isEven/server/server.py
2021-05-18 03:30:52 +00:00

67 lines
3.2 KiB
Python

from flask import Flask, abort, request, redirect, jsonify
app = Flask(__name__)
count = 0
FAKE_ADS = [
'Scarecrow wanted for field in Saskatchewan. Must not be afraid of birds. Email buddybilly@qotmail.com',
'Drink Sprunk cola! The essence of life.',
'Auto Repair Service: Free pick-up and delivery. Try us once, you\'ll never go anywhere again. Email dave57@qotmail.com',
'For Sale: Slightly used headstone. Perfect gift for someone named William Peterson. Email betsy.peterson@qotmail.com',
'Buy isEvenCoin, the hottest new cryptocurrency!',
'Andy\'s hand-made Fingerboxes are built with high quality aluminum. Get yours today!',
'FULL SIZE Mattress. Royal Tonic, 20 year warranty. Like new. Slight urine smell. $40, call 818-555-2301',
'FOR SALE: Complete set of Encyclopedia Britannica, 45 volumes. $1000. No longer needed. Got married, wife knows everything. Call 5435553442.',
'SURGEON WANTED for a new heath clinic opening in SF. No experience needed. Must have own tools. Call 407-555-5400',
'FOR SALE: outdoor nativity scene. No Jesus, Mary, or Joseph. $50 OBO call 344-555-6425',
'PONY FOR SALE. Looks like a small horse. $900. 480-555-6341',
'Lost- Donkey, wearing a pink halter, Monterey Center- 269-555-6234',
'For sale: human skull. Used once only. $200 OBO Dr. Scott Tyler, 454-555-6533',
'TIRED OF WORKING FOR ONLY $9.75 PER HOUR? We offer profit sharing and flexible hours. Starting pay: $5-$7 per hour. Call 413-555-3451',
'1995 NISSAN Maxima, green, leather, loaded, CD, auto start, sunroof, 4-door, great condtion, NOT FOR SALE',
'FOR SALE - collection of old people call 253-555-7212',
'Looking for someone to do yard work. Must have a hoolahoop. 760-555-7562',
'HONDA CIVIC \'96, AM/FM/CD, low miles, Good condition. Speaks Spanish $3500 339-555-6289',
'WANTED: Air Traffic Control. No Exp. Needed; we train, HS grads 17-34. Great pay, benefits. Must relocate. Call 284-555-7133',
'HELP WANTED: Child Care provider. Apply in person, Jack & Kill Childcare, 1905 NW Smith. NO PHONE CALLS',
'CHINA CABINET, buffet, hutch solid pine, 6.5 tall x 4.5 wide, lighted windows. few cat scratches but cat has died. $700. Call 435-555-6421',
'WILL the person who got hit in the head with a tomato in the 1950\'s please contact 414-555-4536',
]
@app.route('/')
def index():
return redirect('https://isevenapi.xyz')
@app.route('/api', strict_slashes=False)
def api():
return 'isEven API root'
@app.route('/api/iseven/<number>', strict_slashes=False)
def isEven(number):
global count
count += 1
try:
number = int(number)
if number < 0 or number > 999999:
res = jsonify(dict(
error='Number out of range. Upgrade to isEven API Premium or Enterprise.',
))
res.status_code = 401
return res
else:
res = jsonify(dict(
iseven=bool(number % 2 == 0),
ad=FAKE_ADS[count % len(FAKE_ADS)],
))
return res
except:
res = jsonify(dict(
error='Invalid number.',
))
res.status_code = 400
return res
if __name__ == '__main__':
app.run(debug=False, host='0.0.0.0', port=5006)