Skip to content

Commit

Permalink
Extra feature added
Browse files Browse the repository at this point in the history
  • Loading branch information
aryan29 committed Dec 18, 2019
1 parent 71a178b commit 519edee
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Week-1/aryan29/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
## License
Expand Down
22 changes: 20 additions & 2 deletions Week-1/aryan29/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 519edee

Please sign in to comment.