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
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
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:
@hkamran80
hkamran80 / useful_regularexpressions
Created June 28, 2019 03:22
Useful regular expressions
\#.* = Remove all comments (Python)
@hkamran80
hkamran80 / search.py
Created September 11, 2019 04:12
Simple Google Search in Python
from bs4 import BeautifulSoup
import requests
url = "https://google.com/search?q=python"
headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15"}
r = requests.get(url, headers=headers)
print(r.status_code)
page = BeautifulSoup(r.content, "html.parser")
@hkamran80
hkamran80 / full_play.js
Last active February 25, 2020 19:51
Full Player for Gameinc.io
// ==UserScript==
// @name Gameinc.io Full Player
// @namespace hkamran80
// @version 1.0
// @description Full play bot for Gameinc.io
// @author H. Kamran
// @match http://gameinc.io/?use_fp_mode=true
// @grant none
// ==/UserScript==