Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
command_lst = command.lower().split()
command_dic = {
"specification":"",
"keyword":"",
"criteria":"ratings",
"sorting_order":"top",
"limit":"10",
"sellers_or_sources":"sellers"
}
# lists for checing the commend
query_type_lst = ["bars", "companies", "countries", "regions"]
sorting_criteria_lst = ["cocoa", "ratings", "bars_sold"]
sorting_order_lst = ["top", "bottom"]
specification_lst = ["sellcountry", "sourcecountry", "sellregion", "sourceregion", "country", "region", "sellers", "sources"]
sellers_or_sources_lst = ["sellers", "sources"]
if_valid = True
# check user's command line
for command in command_lst:
# query type
if command in query_type_lst:
command_dic["query_type"] = command
# sorting criteria
elif command in sorting_criteria_lst:
command_dic["criteria"] = command
# for countries and regions: sellers / sources
elif command in sellers_or_sources_lst:
command_dic["sellers_or_sources"] = command
# number of matches & specifications
elif "=" in command:
lst = command.split("=")
for ele in lst:
# top/bottom & limit
if ele in sorting_order_lst:
command_dic["sorting_order"] = lst[0]
command_dic["limit"] = lst[1]
# specifications
elif ele in specification_lst:
if lst[0] == "sellcountry":
command_dic["specification"] = "c1.Alpha2"
elif lst[0] == "sourcecountry":
command_dic["specification"] = "c2.Alpha2"
elif lst[0] == "sellregion":
command_dic["specification"] = "c1.Region"
elif lst[0] == "sourceregion":
command_dic["specification"] = "c2.Region"
elif lst[0] == "country":
command_dic["specification"] = "Alpha2"
else:
command_dic["specification"] = lst[0].title()
command_dic["keyword"] = lst[1].title()
else:
if_valid = False
if if_valid == False:
print("Command not recognized: ", command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.