├── BookValue.py ├── CSV.py ├── DateDiff.py ├── NetgearLog.py ├── README.md ├── junkcount.py └── mailcount.py /BookValue.py: -------------------------------------------------------------------------------- 1 | # 2023-11-30 2 | # Calculate Shakepay crypto book value from the 3 | # transaction summary CSV file. 4 | import csv 5 | import clipboard 6 | 7 | with open('Data/transactions_summary.csv', mode='r') as csv_file: 8 | csv_reader = csv.DictReader(csv_file) 9 | line_count = 0 10 | book_value = 0 11 | for row in csv_reader: 12 | if line_count == 0: 13 | # print(f'Column names are {", ".join(row)}') 14 | line_count += 1 15 | 16 | if row["Transaction Type"] == "purchase/sale": 17 | line_count += 1 18 | book_value += int(row["Amount Debited"]) 19 | print(f'\nProcessed {line_count} lines.') 20 | print(f'Book value ${book_value}.') 21 | clipboard.set(str(book_value)) -------------------------------------------------------------------------------- /CSV.py: -------------------------------------------------------------------------------- 1 | # Program to re-order and remove columns from CSV data. 2 | # Author: Ian D. Davies 3 | # Date: June 24th, 2013 4 | # --------------------------------------------------------------------- 5 | # Last Updated: July 5, 2013 6 | # Reason: Change some variable names to make them more generic. 7 | 8 | import clipboard 9 | import console 10 | import csv 11 | 12 | text = clipboard.get() 13 | csvLines = text.splitlines() 14 | row = len(csvLines) 15 | 16 | cvs_data = csv.reader(csvLines) 17 | headers = next(cvs_data) 18 | for row in cvs_data: 19 | csv_line = row[2].strip(' ') + ', ' + row[5].strip(' ') + ', ' + row[4].strip(' ') 20 | print csv_line 21 | 22 | print 'done.' 23 | -------------------------------------------------------------------------------- /DateDiff.py: -------------------------------------------------------------------------------- 1 | # Program to calculate the days between two dates. 2 | # Author: Ian D. Davies 3 | # Date: October 8, 2014 4 | # --------------------------------------------------------------------- 5 | import datetime 6 | 7 | today = datetime.date.today() 8 | SomeDate = datetime.date(2018, 11, 11) 9 | diff = SomeDate - today 10 | print 'Somedate is', diff.days, 'day(s) away' 11 | -------------------------------------------------------------------------------- /NetgearLog.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | 3 | def reformatDateTime(DTString): 4 | # Reformat the time stamp to ISO (YYYY-MM-DD HH:MM:SS) 5 | timeStamp = datetime.strptime(DTString, "%b %d %Y %H:%M:%S") 6 | 7 | timeString=timeStamp.strftime("%Y-%m-%d %H:%M:%S") 8 | return (timeString) 9 | 10 | def main(): 11 | 12 | with open("Data/NetgearLogIn.txt") as f: 13 | with open("Data/NetgearLogOut.txt", "w") as f1: 14 | for line in f: 15 | # Extract date and tiem stamp. 16 | splitLine = (line.split(",")) 17 | monthDay = splitLine[-2] 18 | logYear = splitLine[-1] 19 | monthDay = monthDay.strip() 20 | logYear = logYear.strip() 21 | 22 | # Reformat date and time 23 | stringDate = (reformatDateTime(monthDay + " " + logYear)) 24 | 25 | # Put the timestamp at the start of 26 | # the line and write it out to the 27 | # new log file. 28 | fline=(stringDate+" "+splitLine[0]) 29 | f1.write(fline+"\n") 30 | 31 | print("Done...") 32 | 33 | 34 | if __name__ == '__main__': 35 | main() 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Pythonista 2 | ========== 3 | 4 | Useful scripts for iOS Pythonista app. 5 | 6 | - **CSV.py** - Show how to manipulate comma separated values (CSV) yanked from the system clipboard. 7 | - **DateDiff.py** - Use date arithmetic to show days between to dates. 8 | -------------------------------------------------------------------------------- /junkcount.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | small script to check for unread count on imap junk and blocked mailboxes 4 | """ 5 | import sys 6 | import imaplib 7 | import keychain 8 | import clipboard 9 | import shortcuts 10 | 11 | # keychain.set_password('IMAP', 'HSE', ' ') 12 | # keychain.set_password('IMAP', 'LKD', ' ') 13 | 14 | IMAPSERVER = 'imap.bell.net' 15 | USER1 = 'iddavies@sympatico.ca' 16 | PASSWORD1 = keychain.get_password('IMAP', 'HSE') 17 | 18 | USER2 = 'ianddavies@sympatico.ca' 19 | PASSWORD2 = keychain.get_password('IMAP', 'LKD') 20 | 21 | def get_unread_mail_count(USER, PASSWORD) : 22 | try: 23 | mail = imaplib.IMAP4_SSL(IMAPSERVER) 24 | mail.login(USER, PASSWORD) 25 | mail.select("Junk/Blocked", True) # connect to junk folder. 26 | return_code, mail_ids = mail.search(None, 'UnSeen') 27 | # print(mail_ids[0].split()) 28 | # print(mail_ids[0].split(b' ')) 29 | count = len(mail_ids[0].split()) 30 | # count = len(mail_ids[0].split(b' ')) 31 | mail.close() 32 | mail.logout() 33 | except: 34 | count = 100 35 | 36 | # print(count) 37 | return (count) 38 | 39 | def main(): 40 | # If Shortcuts name is passed in the 41 | # command line, use it. Otherwise 42 | # default to "Goodnight 1". 43 | if len(sys.argv) - 1==0: 44 | shortcutName="Goodnight 1" 45 | else: 46 | shortcutName = sys.argv[1] 47 | 48 | count=500 49 | count = get_unread_mail_count(USER1, PASSWORD1) 50 | count = count + get_unread_mail_count(USER2, PASSWORD2) 51 | 52 | # clipboard.set(str(count)) 53 | print(count) 54 | # shortcuts.open_shortcuts_app(name=shortcutName) 55 | 56 | if __name__ == '__main__': 57 | main() 58 | -------------------------------------------------------------------------------- /mailcount.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """ 3 | small script to check for unread count on imap inbox 4 | """ 5 | import sys 6 | import imaplib 7 | import keychain 8 | import clipboard 9 | import shortcuts 10 | 11 | # keychain.set_password('IMAP', 'HSE', ' ') 12 | # keychain.set_password('IMAP', 'LKD', ' ') 13 | 14 | IMAPSERVER = 'imap.bell.net' 15 | USER1 = 'iddavies@sympatico.ca' 16 | PASSWORD1 = keychain.get_password('IMAP', 'HSE') 17 | 18 | USER2 = 'ianddavies@sympatico.ca' 19 | PASSWORD2 = keychain.get_password('IMAP', 'LKD') 20 | 21 | def get_unread_mail_count(USER, PASSWORD) : 22 | try: 23 | mail = imaplib.IMAP4_SSL(IMAPSERVER) 24 | mail.login(USER, PASSWORD) 25 | mail.select("inbox", True) # connect to inbox. 26 | return_code, mail_ids = mail.search(None, 'UnSeen') 27 | # count = len(mail_ids[0].split(b' ')) 28 | # 2022-11-03 Fix an issue where count was always one over the actual count. 29 | count = len(mail_ids[0].split()) 30 | mail.close() 31 | mail.logout() 32 | except: 33 | count = 0 34 | 35 | # print(count) 36 | return (count) 37 | 38 | def main(): 39 | # If Shortcuts name is passed in the 40 | # command line, use it. Otherwise 41 | # default to "Goodnight 1". 42 | if len(sys.argv) - 1==0: 43 | shortcutName="Goodnight 1" 44 | else: 45 | shortcutName = sys.argv[1] 46 | 47 | count = get_unread_mail_count(USER1, PASSWORD1) 48 | # print(count) 49 | 50 | count = count + get_unread_mail_count(USER2, PASSWORD2) 51 | # print(count) 52 | 53 | clipboard.set(str(count)) 54 | # print(count) 55 | shortcuts.open_shortcuts_app(name=shortcutName) 56 | 57 | if __name__ == '__main__': 58 | main() 59 | 60 | --------------------------------------------------------------------------------