Add API fields to command line

main
Jeff Moe 2023-09-27 13:05:11 -06:00
parent 6dab374ff1
commit 30a856df53
1 changed files with 306 additions and 10 deletions

View File

@ -24,7 +24,6 @@ import requests
parser = argparse.ArgumentParser()
parser.add_argument(
"-a",
"--api",
help="API URL (default https://xeno-canto.org/api/2/recordings)",
type=str,
@ -32,21 +31,14 @@ parser.add_argument(
default="https://xeno-canto.org/api/2/recordings",
)
parser.add_argument(
"-q",
"--query",
help="Search Query (default None)",
type=str,
required=False,
default="",
)
args = parser.parse_args()
API_URL = args.api
QUERY = args.query
'''
Upstream API https://xeno-canto.org/explore/api
"""
also: an array with the identified background species in the recording
animal-seen: was the recorded animal seen?
auto: automatic (non-supervised) recording?
@ -84,7 +76,311 @@ QUERY = args.query
type: the sound type of the recording (combining both predefined terms such as 'call' or 'song' and additional free text options)
uploaded: the date that the recording was uploaded to xeno-canto
url: the URL specifying the details of this recording
'''
"""
parser.add_argument(
"--also",
help="an array with the identified background species in the recording",
type=str,
required=False,
default="",
)
parser.add_argument(
"--animal-seen",
help="was the recorded animal seen?",
type=str,
required=False,
default="",
)
parser.add_argument(
"--auto",
help="(non-supervised) recording?",
type=str,
required=False,
default="",
)
parser.add_argument(
"--bird-seen",
help="despite the field name (which was kept to ensure backwards compatibility), this field indicates whether the recorded animal was seen",
type=str,
required=False,
default="",
)
parser.add_argument(
"--cnt",
help="the country where the recording was made",
type=str,
required=False,
default="",
)
parser.add_argument(
"--date",
help="the date that the recording was made",
type=str,
required=False,
default="",
)
parser.add_argument(
"--dvc",
help="recording device used",
type=str,
required=False,
default="",
)
parser.add_argument(
"--en",
help="the English name of the species",
type=str,
required=False,
default="",
)
parser.add_argument(
"--file",
help="the original file name of the audio file",
type=str,
required=False,
default="",
)
parser.add_argument(
"--file-name",
help="the URL to the audio file",
type=str,
required=False,
default="",
)
parser.add_argument(
"--gen",
help="the generic name of the species",
type=str,
required=False,
default="",
)
parser.add_argument(
"--group",
help="the group to which the species belongs (birds, grasshoppers, bats)",
type=str,
required=False,
default="",
)
parser.add_argument(
"--id",
help="the catalogue number of the recording on xeno-canto",
type=str,
required=False,
default="",
)
parser.add_argument(
"--lat",
help="the latitude of the recording in decimal coordinates",
type=str,
required=False,
default="",
)
parser.add_argument(
"--length",
help="the length of the recording in minutes",
type=str,
required=False,
default="",
)
parser.add_argument(
"--lic",
help="the URL describing the license of this recording",
type=str,
required=False,
default="",
)
parser.add_argument(
"--lng",
help="the longitude of the recording in decimal coordinates",
type=str,
required=False,
default="",
)
parser.add_argument(
"--loc",
help="the name of the locality",
type=str,
required=False,
default="",
)
parser.add_argument(
"--method",
help="the recording method (field recording, in the hand, etc.)",
type=str,
required=False,
default="",
)
parser.add_argument(
"--mic",
help="microphone used",
type=str,
required=False,
default="",
)
parser.add_argument(
"--osci",
help="an object with the urls to the three versions of oscillograms",
type=str,
required=False,
default="",
)
parser.add_argument(
"--playback-used",
help="was playback used to lure the animal?",
type=str,
required=False,
default="",
)
parser.add_argument(
"--q",
help="the current quality rating for the recording",
type=str,
required=False,
default="",
)
parser.add_argument(
"--rec",
help="the name of the recordist",
type=str,
required=False,
default="",
)
parser.add_argument(
"--regnr",
help="registration number of specimen (when collected)",
type=str,
required=False,
default="",
)
parser.add_argument(
"--rmk",
help="additional remarks by the recordist",
type=str,
required=False,
default="",
)
parser.add_argument(
"--sex",
help="the sex of the animal",
type=str,
required=False,
default="",
)
parser.add_argument(
"--smp",
help="sample rate",
type=str,
required=False,
default="",
)
parser.add_argument(
"--sono",
help="an object with the urls to the four versions of sonograms",
type=str,
required=False,
default="",
)
parser.add_argument(
"--sp",
help="the specific name (epithet) of the species",
type=str,
required=False,
default="",
)
parser.add_argument(
"--ssp",
help="the subspecies name (subspecific epithet)",
type=str,
required=False,
default="",
)
parser.add_argument(
"--stage",
help="the life stage of the animal (adult, juvenile, etc.)",
type=str,
required=False,
default="",
)
parser.add_argument(
"--temperature",
help="temperature during recording (applicable to specific groups only)",
type=str,
required=False,
default="",
)
parser.add_argument(
"--time",
help="the time of day that the recording was made",
type=str,
required=False,
default="",
)
parser.add_argument(
"--type",
help="the sound type of the recording (combining both predefined terms such as 'call' or 'song' and additional free text options)",
type=str,
required=False,
default="",
)
parser.add_argument(
"--uploaded",
help="the date that the recording was uploaded to xeno-canto",
type=str,
required=False,
default="",
)
parser.add_argument(
"--url",
help="the URL specifying the details of this recording",
type=str,
required=False,
default="",
)
args = parser.parse_args()
API_URL = args.api
QUERY = args.query
# API fields
ALSO = args.also
ANIMAL_SEEN = args.animal_seen
AUTO = args.auto
BIRD_SEEN = args.bird_seen
CNT = args.cnt
DATE = args.date
DVC = args.dvc
EN = args.en
FILE = args.file
FILE_NAME = args.file_name
GEN = args.gen
GROUP = args.group
ID = args.id
LAT = args.lat
LENGTH = args.length
LIC = args.lic
LNG = args.lng
LOC = args.loc
METHOD = args.method
MIC = args.mic
OSCI = args.osci
PLAYBACK_USED = args.playback_used
Q = args.q
REC = args.rec
REGNR = args.regnr
RMK = args.rmk
SEX = args.sex
SMP = args.smp
SONO = args.sono
SP = args.sp
SSP = args.ssp
STAGE = args.stage
TEMPERATURE = args.temperature
TIME = args.time
TYPE = args.type
UPLOADED = args.uploaded
URL = args.url
def print_json(jsn):