├── GoldRate.py ├── README.md ├── YoutubeSubCOunt.py ├── geekfor geek.py ├── goldRateIndia.py ├── stale_outputs_checked ├── stock.py ├── texttospeech.py └── weather.py /GoldRate.py: -------------------------------------------------------------------------------- 1 | import requests 2 | __author__ = "soumil nitin shah " 3 | 4 | headers = { 5 | 'Accept-Encoding': 'gzip, deflate, sdch', 6 | 'Accept-Language': 'en-US,en;q=0.8', 7 | 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36', 8 | 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 9 | 'Referer': 'http://www.wikipedia.org/', 10 | 'Connection': 'keep-alive', 11 | } 12 | 13 | 14 | url = " https://data-asg.goldprice.org/dbXRates/USD" 15 | 16 | r = requests.get(url=url, headers=headers) 17 | data = r.json() 18 | 19 | gold_price = data["items"][0]["xauPrice"] 20 | print(gold_price) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hacking-API-from-website-Python 2 | hacking-API-from-website 3 | 4 | check the tutorial on Youtube 5 | https://www.youtube.com/watch?v=9HMfQACLN3Q&t=283s 6 | -------------------------------------------------------------------------------- /YoutubeSubCOunt.py: -------------------------------------------------------------------------------- 1 | from apiclient.discovery import build 2 | 3 | 4 | class YoutubeSubscriberCount(object): 5 | def __init__(self, api_key = 'YOUR KEY '): 6 | self.api_key = api_key 7 | self.youtube = build('youtube', 'v3', developerKey=api_key) 8 | 9 | @property 10 | def get(self): 11 | res = self.youtube.channels().list(id="UC_eOodxvwS_H7x2uLQa-svw", part="statistics").execute() 12 | return res['items'][0]['statistics']['subscriberCount'] 13 | 14 | obj = YoutubeSubscriberCount() 15 | print("Youtube Subscribers are {}".format(obj.get)) 16 | 17 | -------------------------------------------------------------------------------- /geekfor geek.py: -------------------------------------------------------------------------------- 1 | 2 | import requests 3 | 4 | headers = { 5 | 'Accept-Encoding': 'gzip, deflate, sdch', 6 | 'Accept-Language': 'en-US,en;q=0.8', 7 | 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36', 8 | 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 9 | 'Referer': 'http://www.wikipedia.org/', 10 | 'Connection': 'keep-alive', 11 | } 12 | 13 | url = 'https://ide.geeksforgeeks.org/main.php' 14 | 15 | 16 | code=''' 17 | a=input() 18 | print(a) 19 | ''' 20 | 21 | params= { 22 | 'lang': 'Python3', 23 | 'code': code, 24 | 'input':'soumil shah', 25 | 'save': True 26 | } 27 | 28 | response = requests.post(url,data=params) 29 | print(response.json()) 30 | data = response.json() 31 | 32 | print(data['output']) 33 | print(data['memory']) 34 | 35 | 36 | -------------------------------------------------------------------------------- /goldRateIndia.py: -------------------------------------------------------------------------------- 1 | try: 2 | import requests 3 | from bs4 import BeautifulSoup 4 | except Exception as e: 5 | print('Some Modules are Missing {}'.formate(e)) 6 | 7 | 8 | class Goldrate(object): 9 | 10 | def __init__(self): 11 | 12 | self.__headers = { 13 | 'Accept-Encoding': 'gzip, deflate, sdch', 14 | 'Accept-Language': 'en-US,en;q=0.8', 15 | 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36', 16 | 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 17 | 'Referer': 'http://www.wikipedia.org/', 18 | 'Connection': 'keep-alive', 19 | } 20 | self.url = " https://www.paisabazaar.com/gold-rate/" 21 | 22 | @property 23 | def get(self): 24 | """ 25 | 26 | :return: String value for Gold Rates 27 | """ 28 | 29 | r = requests.get(url=self.url, headers=self.__headers) 30 | soup = BeautifulSoup(r.text, 'html.parser') 31 | 32 | data = soup.findAll(class_='g-6-s goldRate__price goldRatePriceHighLite') 33 | tem = [] 34 | for x in data: 35 | val = x.text[3:] 36 | tem.append(val) 37 | 38 | break 39 | return tem[0] 40 | 41 | 42 | if __name__ == "__main__": 43 | obj = Goldrate() 44 | data = obj.get 45 | print("Soumil Gold Rates in India :\t{}".format(data)) 46 | 47 | -------------------------------------------------------------------------------- /stale_outputs_checked: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soumilshah1995/hacking-API-from-website-Python/dfd208ab33a42c8a3fc0cc569238e851052dc526/stale_outputs_checked -------------------------------------------------------------------------------- /stock.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import re 4 | 5 | 6 | class AppleStock(object): 7 | def __init__(self): 8 | self.__headers={ 9 | 'Accept-Encoding': 'gzip, deflate, sdch', 10 | 'Accept-Language': 'en-US,en;q=0.8', 11 | 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36', 12 | 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 13 | 'Referer': 'http://www.wikipedia.org/', 14 | 'Connection': 'keep-alive'} 15 | 16 | self.__query_string = { 17 | 'ei':'IfUsXc2oJY2J5wKngriIAQ', 18 | 'yv':'3', 19 | 'async': 'mids:/m/07zmbvf,currencies:,_fmt:jspb'} 20 | self.__url = "https://www.google.com/async/finance_wholepage_price_updates" 21 | 22 | @property 23 | def get(self): 24 | response = requests.get(url=self.__url, headers=self.__headers,params=self.__query_string) 25 | data = response.text 26 | pattern = re.compile(r'"AAPL","+\d{2,4}[/.]\d{1,2}"') 27 | matches = pattern.finditer(data) 28 | for match in matches: 29 | stock_data = match.group() 30 | 31 | return stock_data 32 | 33 | obj = AppleStock() 34 | print(obj.get) -------------------------------------------------------------------------------- /texttospeech.py: -------------------------------------------------------------------------------- 1 | 2 | import requests 3 | 4 | headers = { 5 | 'Accept-Encoding': 'gzip, deflate, sdch', 6 | 'Accept-Language': 'en-US,en;q=0.8', 7 | 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36', 8 | 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 9 | 'Referer': 'http://www.wikipedia.org/', 10 | 'Connection': 'keep-alive', 11 | } 12 | 13 | url = 'https://text-to-speech-demo.ng.bluemix.net/api/v1/synthesize?t' 14 | 15 | params= { 16 | 'text': 'hello everyone i am going to teach you python', 17 | 'voice': 'en-US_AllisonV2Voice', 18 | 'download': True, 19 | 'accept': 'audio/mp3' 20 | } 21 | 22 | response = requests.get(url, headers=headers,params=params) 23 | print(response.text) 24 | 25 | 26 | with open('hackerrr.mp3','wb') as f: 27 | f.write(response.content) 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /weather.py: -------------------------------------------------------------------------------- 1 | 2 | import requests 3 | from bs4 import BeautifulSoup 4 | import random 5 | 6 | 7 | def random_proxy(): 8 | url = 'https://www.sslproxies.org/' 9 | 10 | headers = { 11 | 'Accept-Encoding': 'gzip, deflate, sdch', 12 | 'Accept-Language': 'en-US,en;q=0.8', 13 | 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36', 14 | 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 15 | 'Referer': 'http://www.wikipedia.org/', 16 | 'Connection': 'keep-alive', 17 | } 18 | 19 | 20 | r = requests.get(url=url, headers=headers) 21 | soup = BeautifulSoup(r.text, 'html.parser') 22 | 23 | random_ip = [] 24 | random_port = [] 25 | 26 | # Get the Random IP Address 27 | for x in soup.findAll('td')[::8]: 28 | random_ip.append(x.get_text()) 29 | 30 | # Get Their Port 31 | for y in soup.findAll('td')[1::8]: 32 | random_port.append(y.get_text()) 33 | 34 | # Zip together 35 | z = list(zip(random_ip,random_port)) 36 | 37 | number = random.randint(0, len(z)-50) 38 | ip_random = z[number] 39 | 40 | ip_random_string = "{}:{}".format(ip_random[0],ip_random[1]) 41 | 42 | 43 | proxy = {'https':ip_random_string} 44 | 45 | return proxy 46 | 47 | 48 | def proxy_request(request_type, url, **kwargs): 49 | while True: 50 | try: 51 | proxy = random_proxy() 52 | print("{} using proxy".format(proxy)) 53 | r = requests.request(request_type, url, proxies=proxy, timeout=8, **kwargs) 54 | return r 55 | break 56 | except: 57 | pass 58 | 59 | def main(): 60 | headers = { 61 | 'Accept-Encoding': 'gzip, deflate, sdch', 62 | 'Accept-Language': 'en-US,en;q=0.8', 63 | 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36', 64 | 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 65 | 'Referer': 'http://www.wikipedia.org/', 66 | 'Connection': 'keep-alive', 67 | } 68 | 69 | params= { 70 | 'apiKey': 'd522aa97197fd864d36b418f39ebb323', 71 | 'format': 'json', 72 | 'geocode': '42.361145,-71.057083', 73 | 'language': 'en-US', 74 | 'units':'e' 75 | } 76 | 77 | r2 = proxy_request(request_type='get', url='https://api.weather.com/v2/turbo/vt1observation',headers=headers, params=params) 78 | r2_data = r2.json() 79 | 80 | dew_point = r2_data["vt1observation"]["dewPoint"] 81 | feelsLike = r2_data["vt1observation"]["feelsLike"] 82 | humidity = r2_data["vt1observation"]["humidity"] 83 | observationTime = r2_data["vt1observation"]["observationTime"] 84 | temperature = r2_data["vt1observation"]["temperature"] 85 | visibility = r2_data["vt1observation"]["visibility"] 86 | windspeed = r2_data["vt1observation"]["windSpeed"] 87 | winddegree = r2_data["vt1observation"]["windDirDegrees"] 88 | winddirection = r2_data["vt1observation"]["windDirCompass"] 89 | 90 | return dew_point,feelsLike,humidity,observationTime,temperature,visibility,windspeed,winddegree,winddirection 91 | 92 | 93 | if __name__ == "__main__": 94 | print(main()) 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | --------------------------------------------------------------------------------