Skip to content

Instantly share code, notes, and snippets.

View Ovicron's full-sized avatar
🐜

Ovicron

🐜
View GitHub Profile
@Ovicron
Ovicron / between_markers.py
Created November 13, 2020 23:46
between_markers.py
def between_markers(text: str, begin: str, end: str) -> str:
a = text.index(begin) + len(begin) if begin in text else 0
b = text.index(end) if end in text else len(text)
return text[a:b]
if __name__ == '__main__':
print('Example:')
print(between_markers('What is >apple<', '>', '<'))
@Ovicron
Ovicron / remove_all_before.py
Created November 11, 2020 22:34
removes all element before a given int inside a list.
def remove_all_before(items, border):
if not items:
return items
nl = []
for i in range(len(items)):
if items[i] == border:
nl.append(items[i:])
elif border not in items:
class Pizza:
def __init__(self, sides, ingredients):
self.ingredients = ingredients
self.sides = sides
@classmethod
def hawaiian(cls):
return cls(['garlic bread', 'coke'], ['ham', 'cheese', 'tomato sauce'])
@Ovicron
Ovicron / decorator2.py
Created October 18, 2020 23:44
times run time of functioon
import time
def time_it(func):
def wrapper(*args, **kwargs):
start_time = time.time()
return_func = func(*args, **kwargs)
now = time.time()
print(f"Took {now - start_time:.2f} seconds to complete.")
return return_func
@Ovicron
Ovicron / decorator1.py
Created October 18, 2020 23:31
random id decorator
import random
def random_id(func):
def wrapper(*args, **kwargs):
rv = func(*args, **kwargs)
print(f"Function ID:{random.randint(0, 100)}")
return rv
return wrapper
import pygame
import random
# Constants
WIDTH = 800
HEIGHT = 600
FPS = 75
# Pygame initializations
pygame.init()
import requests
from bs4 import BeautifulSoup
import csv
# Requests the website + telling BS4 how to parse the page.
source = requests.get('https://www.coreyms.com').text
soup = BeautifulSoup(source, 'lxml')
csv_file = open('scraped.csv', 'w')
csv.writer = csv.writer(csv_file)
import webbrowser
import pyperclip
import sys
# ['mapit.py', '870', 'Valencia', 'St.']
if len(sys.argv) > 1:
# ['mapit.py', '870', 'Valencia', 'St.'] --> '870 Valencia St'
address = ' '.join(sys.argv[1:])
else:
@Ovicron
Ovicron / ebay_price_scraper.py
Last active May 6, 2020 16:20
scrapes ebay product and returns price of item
import bs4
import requests
def get_ebay_price(product_url):
res = requests.get(product_url)
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, 'html.parser')
page_elem = soup.select('#prcIsum')
@Ovicron
Ovicron / email_and_number_scraper.py
Last active May 3, 2020 21:18
this will scrape email and phone numbers from your clipboard if you have a full page copied and organizes the numbers/emails together.
#! python3
import re
import pyperclip
import pprint
# Create a regex for phone numbers
phone_regex = re.compile(r'''
# 415-555-0000, 555-0000, (415) 555-0000, 555-0000 ext 12345, ext. 12345, x12345