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
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override |
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
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override |
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
void main() { | |
final myMap ={"foo":1}; | |
print(myMap["bar"]); | |
} |
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
def init_cli(default_buffer, default_time): | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
"-b", | |
dest="buffer", | |
type=buffer_type, | |
default=default_buffer, | |
metavar="[0-100]", | |
help=f"The number of requests [{0}-{100}] from the daily quota to leave remaining (i.e. unconsumed). Defaults to {default_buffer}", | |
) |
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
""" | |
Functions to set up the command line interface. | |
Raises: | |
argparse.ArgumentTypeError: Raised if request buffer is out of range | |
argparse.ArgumentTypeError: Raised if time is neither "now" nor HH:mm | |
argparse.ArgumentTypeError: Raised if time is out of correct range | |
argparse.ArgumentTypeError: Raised if offset is negative or not multiple | |
of 100 |
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
import argparse | |
import re | |
# Allows for more control over the error message in the case of invalid arguments | |
def buffer_type(value, min=0, max=100): | |
value = int(value) | |
if min <= value <= max: | |
return value | |
else: | |
raise argparse.ArgumentTypeError( |
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
if args.exec_time == "now": | |
job() | |
if not done: | |
# Prevent scheduling in case of permanent termination | |
schedule.every().day.at(default_time).do(job) | |
else: | |
schedule.every().day.at(args.exec_time).do(job) | |
while True: | |
if done: |
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
def job(): | |
global remaining_quota | |
global offset | |
global done | |
count = 0 | |
while int(remaining_quota) - buffer > 0: | |
querystring["offset"] = str(offset) | |
response = requests.request("GET", url, headers=headers, params=querystring) | |
if response: | |
content = response.json() |
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
url = "https://unogsng.p.rapidapi.com/search" # endpoint | |
querystring = {"orderby": "date", "subtitle": "english"} # only retrieve shows with English subs and order results by date added | |
# TODO: add API key | |
headers = { | |
"x-rapidapi-key": "insert-api-key-here", | |
"x-rapidapi-host": "unogsng.p.rapidapi.com", | |
} |
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
import time # sleep operations | |
import requests # API requests | |
import json # storing data | |
import schedule # scheduling tasks | |
from _cli import init_cli # Command-line interface | |
default_buffer = 15 # default number of daily requests to be left unconsumed | |
default_time = "21:35" # script execution time defaults to quota reset time | |
args = init_cli(default_buffer, default_time) # initialize CLI |
NewerOlder