From 5f9d63558d71bec49519c7e6f0b5718d1d1ab3ae Mon Sep 17 00:00:00 2001 From: Corey Schafer Date: Tue, 25 Jul 2017 23:12:16 -0600 Subject: [PATCH] Code Examples --- Python-CSV/names.csv | 45 ++++++++++++++++++++++++++++++ Python-CSV/new_names.csv | 45 ++++++++++++++++++++++++++++++ Python-CSV/parse_csv.py | 15 ++++++++++ Python-Patreon-CSV/parse_csv.py | 26 +++++++++++++++++ Python-Patreon-CSV/patrons.csv | 49 +++++++++++++++++++++++++++++++++ random_names.py | 11 ++++++++ 6 files changed, 191 insertions(+) create mode 100644 Python-CSV/names.csv create mode 100644 Python-CSV/new_names.csv create mode 100644 Python-CSV/parse_csv.py create mode 100644 Python-Patreon-CSV/parse_csv.py create mode 100644 Python-Patreon-CSV/patrons.csv create mode 100644 random_names.py diff --git a/Python-CSV/names.csv b/Python-CSV/names.csv new file mode 100644 index 000000000..f657fc4ed --- /dev/null +++ b/Python-CSV/names.csv @@ -0,0 +1,45 @@ +first_name,last_name,email +John,Doe,john-doe@bogusemail.com +Mary,Smith-Robinson,maryjacobs@bogusemail.com +Dave,Smith,davesmith@bogusemail.com +Jane,Stuart,janestuart@bogusemail.com +Tom,Wright,tomwright@bogusemail.com +Steve,Robinson,steverobinson@bogusemail.com +Nicole,Jacobs,nicolejacobs@bogusemail.com +Jane,Wright,janewright@bogusemail.com +Jane,Doe,janedoe@bogusemail.com +Kurt,Wright,kurtwright@bogusemail.com +Kurt,Robinson,kurtrobinson@bogusemail.com +Jane,Jenkins,janejenkins@bogusemail.com +Neil,Robinson,neilrobinson@bogusemail.com +Tom,Patterson,tompatterson@bogusemail.com +Sam,Jenkins,samjenkins@bogusemail.com +Steve,Stuart,stevestuart@bogusemail.com +Maggie,Patterson,maggiepatterson@bogusemail.com +Maggie,Stuart,maggiestuart@bogusemail.com +Jane,Doe,janedoe@bogusemail.com +Steve,Patterson,stevepatterson@bogusemail.com +Dave,Smith,davesmith@bogusemail.com +Sam,Wilks,samwilks@bogusemail.com +Kurt,Jefferson,kurtjefferson@bogusemail.com +Sam,Stuart,samstuart@bogusemail.com +Jane,Stuart,janestuart@bogusemail.com +Dave,Davis,davedavis@bogusemail.com +Sam,Patterson,sampatterson@bogusemail.com +Tom,Jefferson,tomjefferson@bogusemail.com +Jane,Stuart,janestuart@bogusemail.com +Maggie,Jefferson,maggiejefferson@bogusemail.com +Mary,Wilks,marywilks@bogusemail.com +Neil,Patterson,neilpatterson@bogusemail.com +Corey,Davis,coreydavis@bogusemail.com +Steve,Jacobs,stevejacobs@bogusemail.com +Jane,Jenkins,janejenkins@bogusemail.com +John,Jacobs,johnjacobs@bogusemail.com +Neil,Smith,neilsmith@bogusemail.com +Corey,Wilks,coreywilks@bogusemail.com +Corey,Smith,coreysmith@bogusemail.com +Mary,Patterson,marypatterson@bogusemail.com +Jane,Stuart,janestuart@bogusemail.com +Travis,Arnold,travisarnold@bogusemail.com +John,Robinson,johnrobinson@bogusemail.com +Travis,Arnold,travisarnold@bogusemail.com diff --git a/Python-CSV/new_names.csv b/Python-CSV/new_names.csv new file mode 100644 index 000000000..1ff7fcb6d --- /dev/null +++ b/Python-CSV/new_names.csv @@ -0,0 +1,45 @@ +first_name last_name +John Doe +Mary Smith-Robinson +Dave Smith +Jane Stuart +Tom Wright +Steve Robinson +Nicole Jacobs +Jane Wright +Jane Doe +Kurt Wright +Kurt Robinson +Jane Jenkins +Neil Robinson +Tom Patterson +Sam Jenkins +Steve Stuart +Maggie Patterson +Maggie Stuart +Jane Doe +Steve Patterson +Dave Smith +Sam Wilks +Kurt Jefferson +Sam Stuart +Jane Stuart +Dave Davis +Sam Patterson +Tom Jefferson +Jane Stuart +Maggie Jefferson +Mary Wilks +Neil Patterson +Corey Davis +Steve Jacobs +Jane Jenkins +John Jacobs +Neil Smith +Corey Wilks +Corey Smith +Mary Patterson +Jane Stuart +Travis Arnold +John Robinson +Travis Arnold diff --git a/Python-CSV/parse_csv.py b/Python-CSV/parse_csv.py new file mode 100644 index 000000000..c2d6eb270 --- /dev/null +++ b/Python-CSV/parse_csv.py @@ -0,0 +1,15 @@ +import csv + +with open('names.csv', 'r') as csv_file: + csv_reader = csv.DictReader(csv_file) + + with open('new_names.csv', 'w') as new_file: + fieldnames = ['first_name', 'last_name'] + + csv_writer = csv.DictWriter(new_file, fieldnames=fieldnames, delimiter='\t') + + csv_writer.writeheader() + + for line in csv_reader: + del line['email'] + csv_writer.writerow(line) diff --git a/Python-Patreon-CSV/parse_csv.py b/Python-Patreon-CSV/parse_csv.py new file mode 100644 index 000000000..39bc1f8de --- /dev/null +++ b/Python-Patreon-CSV/parse_csv.py @@ -0,0 +1,26 @@ +import csv + +html_output = '' +names = [] + +with open('patrons.csv', 'r') as data_file: + csv_data = csv.DictReader(data_file) + + # We don't want first line of bad data + next(csv_data) + + for line in csv_data: + if line['FirstName'] == 'No Reward': + break + names.append(f"{line['FirstName']} {line['LastName']}") + +html_output += f'

There are currently {len(names)} public contributors. Thank You!

' + +html_output += '\n' + +print(html_output) diff --git a/Python-Patreon-CSV/patrons.csv b/Python-Patreon-CSV/patrons.csv new file mode 100644 index 000000000..865b627da --- /dev/null +++ b/Python-Patreon-CSV/patrons.csv @@ -0,0 +1,49 @@ +FirstName,LastName,Email,Pledge,Lifetime,Status,Country,Start +1 + Reward,"Description I will add your name to the contributors page on my website. + +You will also be eligible for Patreon-only rewards. I will occasionally give away books that I have read, and will choose a Patron at random to receive those.",,,,,, +John,Doe,johndoe@bogusemail.com,10.00,20.00,Ok,,2017-05-06 21:28:06.183108 +Dave,Smith,davesmith@bogusemail.com,5.00,10.00,Ok,,2017-05-29 16:13:58.318920 +Mary,Jacobs,maryjacobs@bogusemail.com,5.00,10.00,Ok,,2017-05-14 07:37:01.074648 +Jane,Stuart,janestuart@bogusemail.com,5.00,25.00,Ok,,2016-12-30 18:12:13 +Tom,Wright,tomwright@bogusemail.com,5.00,15.00,Ok,,2017-04-14 04:02:06.658439 +Steve,Robinson,steverobinson@bogusemail.com,5.00,20.00,Ok,,2017-03-17 02:20:14 +Nicole,Jacobs,nicolejacobs@bogusemail.com,5.00,20.00,Ok,,2017-03-12 17:07:29 +Jane,Wright,janewright@bogusemail.com,5.00,25.00,,,2017-01-14 17:40:06 +Jane,Doe,janedoe@bogusemail.com,2.50,5.00,Ok,,2017-05-14 11:20:50.798440 +Kurt,Wright,kurtwright@bogusemail.com,2.00,2.00,Ok,,2017-06-23 21:12:15.662157 +Kurt,Robinson,kurtrobinson@bogusemail.com,2.00,4.00,Ok,,2017-05-03 03:18:54.877885 +Jane,Jenkins,janejenkins@bogusemail.com,2.00,8.00,Ok,,2017-03-23 16:37:47.708634 +Neil,Robinson,neilrobinson@bogusemail.com,1.50,3.00,Ok,,2017-05-26 19:59:51.013984 +Tom,Patterson,tompatterson@bogusemail.com,1.34,4.02,Ok,,2017-04-27 01:55:12.313799 +Sam,Jenkins,samjenkins@bogusemail.com,1.00,0.00,Ok,,2017-07-16 02:34:47.674287 +Steve,Stuart,stevestuart@bogusemail.com,1.00,1.00,Ok,,2017-06-12 03:32:00.706554 +Maggie,Patterson,maggiepatterson@bogusemail.com,1.00,2.00,Ok,,2017-05-26 01:23:14.097393 +Maggie,Stuart,maggiestuart@bogusemail.com,1.00,2.00,Ok,,2017-05-19 23:11:08.624354 +Jane,Doe,janedoe@bogusemail.com,1.00,3.00,Ok,,2017-04-15 19:40:17.044921 +Steve,Patterson,stevepatterson@bogusemail.com,1.00,3.00,Ok,,2017-04-09 17:14:23.591656 +Dave,Smith,davesmith@bogusemail.com,1.00,3.00,Ok,,2017-04-01 18:35:10.731005 +Sam,Wilks,samwilks@bogusemail.com,1.00,4.00,Ok,,2017-03-01 09:40:56 +Kurt,Jefferson,kurtjefferson@bogusemail.com,1.00,5.00,Ok,,2017-02-24 08:23:05 +Sam,Stuart,samstuart@bogusemail.com,1.00,5.00,Ok,,2017-02-12 00:14:31 +Jane,Stuart,janestuart@bogusemail.com,1.00,5.00,Ok,,2017-02-06 14:52:28 +Dave,Davis,davedavis@bogusemail.com,1.00,0.00,,,2016-11-18 01:37:25 +Sam,Patterson,sampatterson@bogusemail.com,1.00,8.00,Ok,,2016-11-01 11:27:17 +Tom,Jefferson,tomjefferson@bogusemail.com,1.00,10.00,Ok,,2016-09-27 09:56:48 +Jane,Stuart,janestuart@bogusemail.com,1.00,7.00,,,2016-08-09 14:42:25 +Maggie,Jefferson,maggiejefferson@bogusemail.com,1.00,12.00,Ok,,2016-07-26 05:02:16 +No Reward,Description: (None for No Reward),,,,,, +Mary,Wilks,marywilks@bogusemail.com,20.00,60.00,Ok,,2017-04-21 02:44:43.395224 +Neil,Patterson,neilpatterson@bogusemail.com,10.00,80.00,Ok,,2016-11-12 17:49:37 +Corey,Davis,coreydavis@bogusemail.com,6.00,90.00,Ok,,2016-04-01 15:19:52 +Steve,Jacobs,stevejacobs@bogusemail.com,5.00,21.00,Ok,,2017-01-04 19:38:44 +Jane,Jenkins,janejenkins@bogusemail.com,5.00,30.00,Ok,,2017-01-15 17:24:39 +John,Jacobs,johnjacobs@bogusemail.com,3.14,34.54,Ok,,2016-08-23 16:09:25 +Neil,Smith,neilsmith@bogusemail.com,3.00,24.00,Ok,,2016-11-28 02:57:48 +Corey,Wilks,coreywilks@bogusemail.com,2.00,8.00,Ok,,2017-03-26 20:13:08.207869 +Corey,Smith,coreysmith@bogusemail.com,1.00,0.00,Ok,,2017-07-05 01:50:35.171076 +Mary,Patterson,marypatterson@bogusemail.com,1.00,0.00,Ok,,2017-07-04 18:05:23.052059 +Jane,Stuart,janestuart@bogusemail.com,1.00,2.00,Ok,,2017-05-21 19:42:36.098523 +Travis,Arnold,travisarnold@bogusemail.com,1.00,3.00,Ok,,2017-04-19 08:04:33.428559 +John,Robinson,johnrobinson@bogusemail.com,1.00,4.00,Ok,,2017-03-30 14:59:33.850333 +Travis,Arnold,travisarnold@bogusemail.com,1.00,6.00,Ok,,2017-01-28 22:02:57 diff --git a/random_names.py b/random_names.py new file mode 100644 index 000000000..dee0b22c5 --- /dev/null +++ b/random_names.py @@ -0,0 +1,11 @@ +''' Super simple module to get basic random names and emails''' +import random + +random_first = ['John', 'Jane', 'Corey', 'Travis', 'Dave', 'Kurt', 'Neil', 'Sam', 'Mary', 'Maggie', 'Nicole', 'Steve', 'Tom'] +random_last = ['Smith', 'Doe', 'Jenkins', 'Robinson', 'Davis', 'Stuart', 'Jefferson', 'Jacobs', 'Wright', 'Patterson', 'Wilks', 'Arnold'] + +for num in range(20): + first = random.choice(random_first) + last = random.choice(random_last) + email = first.lower() + last.lower() + '@bogusemail.com' + print(f'{first} {last} - {email}')