From 519edeeb513b347c672e08fd893daf40510e0683 Mon Sep 17 00:00:00 2001 From: aryan29 Date: Wed, 18 Dec 2019 16:33:34 +0530 Subject: [PATCH] Extra feature added --- Week-1/aryan29/README.md | 6 ++++++ Week-1/aryan29/api.py | 22 ++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Week-1/aryan29/README.md b/Week-1/aryan29/README.md index 66331c3..4b6073d 100644 --- a/Week-1/aryan29/README.md +++ b/Week-1/aryan29/README.md @@ -56,6 +56,12 @@ Example Image:- ![Server Running Update](https://github.com/aryan29/Git-Freeze/blob/aryan29/week1/Week-1/aryan29/images/Screenshot_20191215-224219.png) We Provide you with Daily Emails and messages regarding whether your server is running or not if it is not Working you will not recive Email so you can switch it on + +## Updates +Added a smart feature to directly compare 2 phones on basis of their spec score just use +```python +python api.py -cm "Asus Zenfone Max Pro M1" "Redmi Mi A2" +``` ## Contributing Feel Free to Contribute and for any suggestions you can mail me at ## License diff --git a/Week-1/aryan29/api.py b/Week-1/aryan29/api.py index 9add93f..1f450ac 100644 --- a/Week-1/aryan29/api.py +++ b/Week-1/aryan29/api.py @@ -69,23 +69,41 @@ def organize(self): else: cprint("Thanks for using us",'magenta') def get_smartprix_code(self,mob_name): + print(mob_name) q=requests.get(f"https://www.smartprix.com/products/?q={mob_name}") s=bs4.BeautifulSoup(q.text,'lxml') sel=s.select(".f-mobiles:nth-child(1) h2 a") st=sel[0]['href'] x=st[st.find("mobiles/")+8:] cprint(f"Smartprix Code -> {x}",'magenta') + def smart_compare(self,mob1,mob2): + q1=requests.get(f"https://www.smartprix.com/products/?q={mob1}") + q2=requests.get(f"https://www.smartprix.com/products/?q={mob2}") + s1=bs4.BeautifulSoup(q1.text,'lxml') + sel1=s1.select(".f-mobiles:nth-child(1) .score-val")[0] + s2=bs4.BeautifulSoup(q2.text,'lxml') + sel2=s2.select(".f-mobiles:nth-child(1) .score-val")[0] + #print(sel2,sel1) + if(int(sel2.text)>int(sel1.text)): + mob1,mob2=mob2,mob1 + cprint(f"{mob1} is better than {mob2} comparing all the features",'cyan') + if __name__ == "__main__": if(len(sys.argv)>1): if(sys.argv[1]=='-j'): Api().organize() elif(sys.argv[1]=='-gc'): - if(sys.argv[2]==''): + if(len(sys.argv)!=3): cprint("Enter a valid mobile name enter -h for help",'cyan') else: Api().get_smartprix_code(sys.argv[2]) + elif(sys.argv[1]=='-cm'): + if(len(sys.argv)!=4): + cprint("Enter a valid mobile name enter -h for help",'cyan') + else: + Api().smart_compare(sys.argv[2],sys.argv[3]) elif(sys.argv[1]=='-h'): - cprint(" -j -> Gets you a json file of Mobiles\n","-gc [Mobile Name]-> Gets you Smartprix Code for a particular Mobile\n","-h -> Help Menu\n",'cyan') + cprint("-j -> Gets you a json file of Mobiles\n"+"-gc [Mobile Name]-> Gets you Smartprix Code for a particular Mobile\n"+"-cm [Mobile 1] [Mobie 2] to compare phones on basis of their spec score\n"+"-h -> Help Menu\n",'cyan') else: cprint("Enter a valid mobile name enter -h for help",'cyan') else: