Skip to content

Instantly share code, notes, and snippets.

View pointofpresence's full-sized avatar
🏠
Working from home

ReSampled pointofpresence

🏠
Working from home
View GitHub Profile
@pointofpresence
pointofpresence / HTTP_requests_and_JSON_parsing.py
Last active March 31, 2024 20:01
Python: Запрос JSON методом GET и парсинг
import requests
url = 'http://maps.googleapis.com/maps/api/directions/json'
params = dict(
origin='Chicago,IL',
destination='Los+Angeles,CA',
waypoints='Joplin,MO|Oklahoma+City,OK',
sensor='false'
)
@pointofpresence
pointofpresence / getopt.py
Last active April 4, 2022 07:24
Created with Copy to Gist
import getopt, sys
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="])
except getopt.GetoptError as err:
# print help information and exit:
print(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
@pointofpresence
pointofpresence / get_opt.py
Last active March 31, 2024 21:08
Python: Получение аргументов командной строки
import getopt
import sys
 
argv = sys.argv[1:]
opts, args = getopt.getopt(argv, 'x:y:')
 
# list of options tuple (opt, value)
print(f'Options Tuple is {opts}')
 
# list of remaining command-line arguments
@pointofpresence
pointofpresence / login_with_cookies.py
Last active March 31, 2024 18:15
Python: Авторизация с использованием cookies
import requests
LOGIN_URL = 'https://examplenotarealpage.com'
headers = {
'accept': 'text/html,application/xhtml+xml,application/xml',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}
response = requests.get(LOGIN_URL, headers=headers, verify=False)
@pointofpresence
pointofpresence / parse_from_HTML.py
Last active April 4, 2022 07:31
Created with Copy to Gist
from bs4 import BeautifulSoup
soup = BeautifulSoup(response.text, 'lxml')
csrf_token = soup.select_one('meta[name="csrf-token"]')['content']
@pointofpresence
pointofpresence / dict_dot_access.py
Created April 4, 2022 13:08
How to use a dot "." to access members of dictionary?
class dotdict(dict):
"""dot.notation access to dictionary attributes"""
__getattr__ = dict.get
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
mydict = {'val':'it works'}
nested_dict = {'val':'nested works too'}
mydict = dotdict(mydict)
mydict.val
@pointofpresence
pointofpresence / get_file_size.py
Last active April 7, 2022 07:19
Python get file size
os.path.getsize("/path/isa_005.mp3")
@pointofpresence
pointofpresence / read_json_from_file.py
Created April 7, 2022 07:20
Python read JSON from file
import json
with open('data.json', 'w') as f:
json.dump(data, f)
@pointofpresence
pointofpresence / set_mp3_tags.py
Last active April 7, 2022 07:22
Python set MP3 tags
import eyed3
audiofile = eyed3.load("song.mp3")
audiofile.tag.artist = "Token Entry"
audiofile.tag.album = "Free For All Comp LP"
audiofile.tag.album_artist = "Various Artists"
audiofile.tag.title = "The Edge"
audiofile.tag.track_num = 3
audiofile.tag.save()
@pointofpresence
pointofpresence / exception_while_using_with_statement.py
Last active April 7, 2022 07:24
Python exception while using 'with' statement
try:
with open( "a.txt" ) as f :
print f.readlines()
except EnvironmentError: # parent of IOError, OSError *and* WindowsError where available
print 'oops'