Skip to content

Instantly share code, notes, and snippets.

View akarsh1995's full-sized avatar
🌐
Finding a startup

Akarsh akarsh1995

🌐
Finding a startup
View GitHub Profile
@akarsh1995
akarsh1995 / create_github_repo.py
Created August 21, 2020 13:51
Create github repo from python itself. Hence automate your workflow.
# get the github api personal access token from here !
# https://github.blog/2013-05-16-personal-api-tokens/
from github3 import GitHub
from github3.repos.repo import Repository
def create_and_get_repo(git_auth, name, description, private):
repo: Repository = git_auth.create_repository(
name=name, description=description, private=private
)
@akarsh1995
akarsh1995 / clean_article.py
Created August 19, 2020 12:30
Clean the article webpage and get the main body of the article.
import requests
from readability import Document
def get_webpage_content(url: str):
response = requests.get(url)
content = ""
if response.ok:
content = response.content
response.close()
@akarsh1995
akarsh1995 / clean_article.py
Created August 19, 2020 12:22
Clean the article webpage and get the main body of the article.
import requests
from readability import Document
def get_webpage_content(url: str):
response = requests.get(url)
content = ""
if response.ok:
content = response.content
response.close()
@akarsh1995
akarsh1995 / duplicate_finder.py
Created August 15, 2020 15:41
If your hard disk is filling up fast try finding the duplicate files in a directory <3 Python script.
from pathlib import Path
from collections import defaultdict
from hashlib import md5
def find_duplicates(directory):
# collect the hashes against file path
duplicate_files_dict = defaultdict(list)
# recursively iterate over each file
@akarsh1995
akarsh1995 / insta_auto_bot.py
Created August 13, 2020 06:31
You must use this automation script to increase your follower count.
# imports
from instapy import InstaPy
from instapy import smart_run
# login credentials
insta_username = '' # <- enter username here
insta_password = '' # <- enter password here
# get an InstaPy session!
# set headless_browser=True to run InstaPy in the background
@akarsh1995
akarsh1995 / requirements.txt
Created August 12, 2020 14:23
Machine Learning (N L P) extract named entities from the text using spaCy.
spacy
@akarsh1995
akarsh1995 / postgres_connection.py
Created August 11, 2020 18:37
For aspiring database administrators. Create database connection using python's SQLAlchemy.
from sqlalchemy import create_engine
default_query = ("select * from pg_catalog.pg_tables where schemaname !="
"'information_schema' and schemaname != 'pg_catalog'")
def create_engine_custom(username, password=None, host='localhost', db=None):
password = ':' + password if password else ''
db = db if db else ''
engine = create_engine(f'postgresql+psycopg2://{username}{password}@{host}/{db}')
return engine
@akarsh1995
akarsh1995 / postgres_connection.py
Created August 11, 2020 18:37
For aspiring database administrators. Create database connection using python's SQLAlchemy.
from sqlalchemy import create_engine
default_query = ("select * from pg_catalog.pg_tables where schemaname !="
"'information_schema' and schemaname != 'pg_catalog'")
def create_engine_custom(username, password=None, host='localhost', db=None):
password = ':' + password if password else ''
db = db if db else ''
engine = create_engine(f'postgresql+psycopg2://{username}{password}@{host}/{db}')
return engine
@akarsh1995
akarsh1995 / download_manager.py
Created August 10, 2020 19:08
Create your own cli download manager using python.
import os
import sys
from pathlib import Path
import requests
from tqdm import tqdm
# get the size of in human readable format
def sizeof_fmt(num):
@akarsh1995
akarsh1995 / events.py
Created August 8, 2020 15:39
Are you into DevOps? Dare you miss this one. Observe FileSystem events and log the changes.
import sys
import time
import logging
from pathlib import Path
from watchdog.observers import Observer
from watchdog.events import LoggingEventHandler
if __name__ == "__main__":
# Set the format for logging info