Skip to content

Instantly share code, notes, and snippets.

@RackReaver
Last active May 10, 2021 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RackReaver/234eb69e512231a105b8f95859ccd8b4 to your computer and use it in GitHub Desktop.
Save RackReaver/234eb69e512231a105b8f95859ccd8b4 to your computer and use it in GitHub Desktop.
python snippets
def append_csv(filename, value):
"""This will append a vaule to a csv file.
args:
filename (str): full path or relative path of the csv file.
value (str): string to append to the csv file.
Return: None
"""
with open(filename, 'a') as openFile:
openFile.write('\n{}'.format(value))
import os
import logging
def log_config():
# Logging configuration
fmtstr = "%(asctime)s: %(levelname)s - %(message)s"
logging.basicConfig(
filename='tracking.log',
level=logging.INFO,
filemode='a',
format=fmtstr
)
# Log when script runs with machine name and script name
logging.info('{} started {}'.format(
socket.gethostname(), os.path.basename(__file__)))
import csv
def read_csv(filename):
"""This will import single column csv files.
args:
filename (str): full path or relative path of the csv file.
Return (list): list of row values in the csv file.
"""
final_list = []
with open(filename, 'r') as openFile:
reader = csv.reader(openFile)
for row in reader:
final_list.append(row[0])
return final_list
from datetime import datetime
today = datetime.now()
plus_days = 7
final_date = today + timedelta(days=int(plus_days))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment