Skip to content

Instantly share code, notes, and snippets.

@hkamran80
hkamran80 / pyargs.md
Created January 16, 2018 18:10 — forked from dideler/pyargs.md
Parsing Command-Line Argument in Python

Command-line arguments in Python show up in sys.argv as a list of strings (so you'll need to import the sys module).

For example, if you want to print all passed command-line arguments:

import sys
print(sys.argv)  # Note the first argument is always the script filename.

Command-line options are sometimes passed by position (e.g. myprogram foo bar) and sometimes by using a "-name value" pair (e.g. myprogram -a foo -b bar).

Here's a simple way to parse command-line pair arguments. It scans the argv list looking for -optionname optionvalue word pairs and places them in a dictionary for easy retrieval. The code is heavily commented to help Python newcomers.

@hkamran80
hkamran80 / pyargs.md
Created January 16, 2018 18:10 — forked from dideler/pyargs.md
Parsing Command-Line Argument in Python

Command-line arguments in Python show up in sys.argv as a list of strings (so you'll need to import the sys module).

For example, if you want to print all passed command-line arguments:

import sys
print(sys.argv)  # Note the first argument is always the script filename.

Command-line options are sometimes passed by position (e.g. myprogram foo bar) and sometimes by using a "-name value" pair (e.g. myprogram -a foo -b bar).

Here's a simple way to parse command-line pair arguments. It scans the argv list looking for -optionname optionvalue word pairs and places them in a dictionary for easy retrieval. The code is heavily commented to help Python newcomers.

@hkamran80
hkamran80 / omercy.py
Created February 23, 2018 01:03 — forked from Krazybug/omercy.py
O'Reilly free ebooks downloader
'''
O'Meirrcy !!!! Download free ebooks from O'Reilly
Usage:
> git clone https://gist.github.com/Krazybug/1ae50814d25b0a1d862dfdf7161ee503
> mv 1ae50814d25b0a1d862dfdf7161ee503 omercy
> cd omercy
> pip install requests
> pip install bs4
> python omercy.py
@hkamran80
hkamran80 / SmartTV2.txt
Last active October 31, 2024 03:01
Pi-hole Blocklist for Smart TVs
# THIS FILE IS NO LONGER BEING MAINTAINED. FOR A MAINTAINED VERSION, PLEASE USE THE VERSION IN THE NEW REPOSITORY.
# Repository: https://github.com/hkamran80/blocklists
# New link for this file: https://raw.githubusercontent.com/hkamran80/blocklists/main/smart-tv
# ------
# This is a blocklist to block Smart TVs sending data home.
# Please help to collect domains!
# It could be that the TV does not receive any more updates or other services no longer work. Please report such an incident.
import sl
from getpass import getpass
schoolloop_subdomain = input("Subdomain: ")
schoolloop_username = input("Username: ")
schoolloop_password = getpass()
s2 = login(schoolloop_subdomain, schoolloop_username, schoolloop_password)
homework = sl.get_homework(s2)
for h in homework:
import sl
from getpass import getpass
schoolloop_subdomain = input("Subdomain: ")
schoolloop_username = input("Username: ")
schoolloop_password = getpass()
s2 = login(schoolloop_subdomain, schoolloop_username, schoolloop_password)
grades = sl.get_grades()
for g in grades:
@hkamran80
hkamran80 / maclookup.py
Created May 14, 2018 14:38
MAC Address Lookup
# MAC Address Lookup
from bs4 import BeautifulSoup
import requests
import sys
mac_send = []
def scan(bs_object, mac_addr):
global mac_send
@hkamran80
hkamran80 / googlelogin_example.py
Last active May 24, 2018 00:19
googlesession_example.py
import googlelogin, getpass
username = "{your_google_email_here}"
password = getpass.getpass()
session = googlelogin.GoogleSession(username, password)
# Will return nothing
session.get("https://plus.google.com")
# Returns the content of the site
@hkamran80
hkamran80 / anagram.py
Created January 1, 2019 18:49
Anagram Finder
"""
Anagram
Contributors:
:: H. Kamran [@hkamran80] (author)
Version: 0.0.1
Last Updated: 2019-01-01, @hkamran80
"""
import requests
@hkamran80
hkamran80 / useful_regularexpressions
Created June 28, 2019 03:22
Useful regular expressions
\#.* = Remove all comments (Python)