Skip to content

Instantly share code, notes, and snippets.

View Vert86's full-sized avatar

Calvert Edwards Vert86

View GitHub Profile
@Vert86
Vert86 / csvMerger.py
Created January 9, 2023 07:55
Python script that merges multiple .csv files into one .csv file
import pandas as pd
import glob
#list of csv files
csv_files = glob.glob('*.csv')
#read csv files into a list of dataframes
df_list = [pd.read_csv(file) for file in csv_files]
@Vert86
Vert86 / pickle_write.py
Created September 19, 2022 14:17
Write a dictionary in bytes, store it somewhere then load it when ready through calling functions
import pickle
def save_dict(dict_to_save, file_path):
with open(file_path, 'wb') as file: #write bytes
pickle.dump(dict_to_save, file)
def load_dict(file_path):
with open(file_path, 'rb') as file: #read the binary data
return pickle.load(file)
@Vert86
Vert86 / find_my_files.py
Created August 31, 2022 11:58
#Find all files in a directory with required extension .py/.sh/.log/.txt
#!/usr/local/bin/python3
#Find all files in a directory with required extension .py/.sh/.log/.txt
import os
req_path=input("Enter your directory path: ")
#req_ex=input("Enter the required files extention .py/.sh/.log/.txt: ")
if os.path.isfile(req_path):
print(f"The given path {req_path} is a file. Please pass only directory path")
else:
all_f_ds=os.listdir(req_path)
@Vert86
Vert86 / watsap.py
Last active August 25, 2022 09:29
OPens up your web browser and allows you to send a whatsapp message
import pywhatkit
import datetime
print(datetime.datetime.now())
# Send message to a contact
phone_number = '+1784xxxxx'
pywhatkit.sendwhatmsg(phone_number, message='Just ignore this message',
time_hour=17, time_min=19,
wait_time=10,
@Vert86
Vert86 / soup.py
Last active August 25, 2022 08:26
Extracting HTML from a website using BeautifulSoup
from bs4 import BeautifulSoup
import requests
rf = requests.get(url='https://subslikescript.com/movie/Titanic-120338')
rf_text = rf.text
my_soup = BeautifulSoup(rf_text, 'lxml')
print(my_soup.prettify())
#find main article
@Vert86
Vert86 / try_except.py
Created August 22, 2022 11:53
Handling annoying errors
try:
num = int(input('Enter Number: '))
print(num)
except ValueError:
print('Invalid Input')
try:
Value = 10/0
except:
@Vert86
Vert86 / my_file.py
Created August 22, 2022 11:39
Reading and writing files
#Ask for a file then open file in read only mode anbd prints contents in console
file1 = input('Enter file:')
with open(file1) as f:
print(f.read())
#Open file in read format then close file
file2 = open("Myfile.txt", 'r')
content = file2.read
#check if readable
print(file2.readable())
@Vert86
Vert86 / GET_no_duplicate.py
Last active August 19, 2022 06:51
Removing duplicates from GET Request list
import requests as r
url = 'https://jsonplaceholder.typicode.com/photos'
response = r.get(url)
#read data into a variable
content = response.json()