Tuesday, January 21, 2020

Find exact count of Instagram followers

from tkinter import *
from bs4 import BeautifulSoup
import re, json, requests, tkinter as tk

def CreateWidgets():
    idLabel = Label(root, text="INSTAGRAM ID:", background="deepskyblue4")
    idLabel.grid(row=0, column=0, padx=5, pady=5)
    root.idEntry = Entry(root, width=30, textvariable=instaID)
    root.idEntry.grid(row=0, column=0, columnspan=2, padx=5, pady=5)
    findBTN = Button(root, width=45, text="FIND EXACT COUNT OF FOLLOWERS", command=exactCount)
    findBTN.grid(row=1, column=0, columnspan=2, padx=5, pady=5)
    findBTN.config(highlightbackground="green")
    followersLabel = Label(root, text="YOUR INSTAGRAM FOLLOWERS IS", background="deepskyblue4")
    followersLabel.grid(row=2, column=0, columnspan=2, padx=5, pady=5)
    followersLabel.config(font=("Courier", 35))
    root.countLabel = Label(root, background="darkslategrey", fg="yellowgreen")
    root.countLabel.config(font=("Courier", 50))

def exactCount():
    insta_id = instaID.get()
    insta_page = requests.get('https://www.instagram.com/'+insta_id)
    soup = BeautifulSoup(insta_page.text, "html.parser")
    script = soup.find('script', text=re.compile('window._sharedData'))
    page_json = script.text.split(' = ', 1)[1].rstrip(';')
    data = json.loads(page_json)
    followers = data['entry_data']['ProfilePage'][0]['graphql']['user']['edge_followed_by']['count']
    root.countLabel.grid(row=3, column=0, padx=5, pady=5, columnspan=2)
    root.countLabel.config(text=str(followers))

root = tk.Tk()
root.geometry("420x350")
root.title("Get details of your instagram account followers")
root.config(background="deepskyblue4")
instaID = StringVar()
CreateWidgets()
root.mainloop()

Saturday, January 18, 2020

Instagram Scraping

import requests
from bs4 import BeautifulSoup

URL = "https://www.instagram.com/{}/"

def scrape(username):
    full_url = URL.format(username)
    r = requests.get(full_url)
    s = BeautifulSoup(r.text,"lxml")
    tag = s.find("meta", attrs = {"name": "description"})
    text = tag.attrs['content']
    main_text = text.split("-")[0]
    return main_text

USERNAME = "iamsahildhamija"
data = scrape(USERNAME)
print(data)

URL Shortner

import urllib.request

def tiny_url(url):
    apiurl = "http://tinyurl.com/api-create.php?url="
    tinyurl = urllib.request.urlopen(apiurl+url).read()
    return tinyurl.decode("utf-8")
url = input("Enter your url to shorten: ")
print(tiny_url(url))

Proxy Crawler

import requests
from bs4 import BeautifulSoup

def crawl_proxies():
    proxies = []
    link = "https://www.sslproxies.org/"
    r = requests.get(link)
    soup = BeautifulSoup(r.text, "lxml")
    for i in soup.find_all("tr")[0:30]:
        try:
            data = i.find_all("td")
            address = data[0].text
            port = data[1].text
            type_ = data[4].text
            proxy = address + ":" + port
            proxies.append({"https":proxy})
        except:
            pass
    return proxies

proxies = crawl_proxies()
print(proxies)

Send Email

import smtplib
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login("sender email id", "sender email password")
message = "Hi! Script Testing!!"
s.sendmail("sender email id", "receiver email id", message)
s.quit()

Get Cricket Live Score

import requests
from bs4 import BeautifulSoup
from time import sleep

url = "http://static.cricinfo.com/rss/livescores.xml"
while True:
    r = requests.get(url)
    while r.status_code is not 200:
        r = requests.get(url)
    soup = BeautifulSoup(r.text, features="lxml")
    data = soup.find_all("description")
    score = data[1].text
    print(score)
    sleep(60)

Check Internet Connection

from urllib.request import urlopen
def checkcon():
    try:
        urlopen('http://sahildhamija.com/', timeout=1)
        return True
    except:
        return False
print(checkcon())