Skip to content

Commit

Permalink
Code Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
CoreyMSchafer committed Jul 26, 2017
1 parent 2165e57 commit 5f9d635
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Python-CSV/names.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
first_name,last_name,email
John,Doe,[email protected]
Mary,Smith-Robinson,[email protected]
Dave,Smith,[email protected]
Jane,Stuart,[email protected]
Tom,Wright,[email protected]
Steve,Robinson,[email protected]
Nicole,Jacobs,[email protected]
Jane,Wright,[email protected]
Jane,Doe,[email protected]
Kurt,Wright,[email protected]
Kurt,Robinson,[email protected]
Jane,Jenkins,[email protected]
Neil,Robinson,[email protected]
Tom,Patterson,[email protected]
Sam,Jenkins,[email protected]
Steve,Stuart,[email protected]
Maggie,Patterson,[email protected]
Maggie,Stuart,[email protected]
Jane,Doe,[email protected]
Steve,Patterson,[email protected]
Dave,Smith,[email protected]
Sam,Wilks,[email protected]
Kurt,Jefferson,[email protected]
Sam,Stuart,[email protected]
Jane,Stuart,[email protected]
Dave,Davis,[email protected]
Sam,Patterson,[email protected]
Tom,Jefferson,[email protected]
Jane,Stuart,[email protected]
Maggie,Jefferson,[email protected]
Mary,Wilks,[email protected]
Neil,Patterson,[email protected]
Corey,Davis,[email protected]
Steve,Jacobs,[email protected]
Jane,Jenkins,[email protected]
John,Jacobs,[email protected]
Neil,Smith,[email protected]
Corey,Wilks,[email protected]
Corey,Smith,[email protected]
Mary,Patterson,[email protected]
Jane,Stuart,[email protected]
Travis,Arnold,[email protected]
John,Robinson,[email protected]
Travis,Arnold,[email protected]
45 changes: 45 additions & 0 deletions Python-CSV/new_names.csv
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions Python-CSV/parse_csv.py
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 26 additions & 0 deletions Python-Patreon-CSV/parse_csv.py
Original file line number Diff line number Diff line change
@@ -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'<p>There are currently {len(names)} public contributors. Thank You!</p>'

html_output += '\n<ul>'

for name in names:
html_output += f'\n\t<li>{name}</li>'

html_output += '\n</ul>'

print(html_output)
49 changes: 49 additions & 0 deletions Python-Patreon-CSV/patrons.csv
Original file line number Diff line number Diff line change
@@ -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,[email protected],10.00,20.00,Ok,,2017-05-06 21:28:06.183108
Dave,Smith,[email protected],5.00,10.00,Ok,,2017-05-29 16:13:58.318920
Mary,Jacobs,[email protected],5.00,10.00,Ok,,2017-05-14 07:37:01.074648
Jane,Stuart,[email protected],5.00,25.00,Ok,,2016-12-30 18:12:13
Tom,Wright,[email protected],5.00,15.00,Ok,,2017-04-14 04:02:06.658439
Steve,Robinson,[email protected],5.00,20.00,Ok,,2017-03-17 02:20:14
Nicole,Jacobs,[email protected],5.00,20.00,Ok,,2017-03-12 17:07:29
Jane,Wright,[email protected],5.00,25.00,,,2017-01-14 17:40:06
Jane,Doe,[email protected],2.50,5.00,Ok,,2017-05-14 11:20:50.798440
Kurt,Wright,[email protected],2.00,2.00,Ok,,2017-06-23 21:12:15.662157
Kurt,Robinson,[email protected],2.00,4.00,Ok,,2017-05-03 03:18:54.877885
Jane,Jenkins,[email protected],2.00,8.00,Ok,,2017-03-23 16:37:47.708634
Neil,Robinson,[email protected],1.50,3.00,Ok,,2017-05-26 19:59:51.013984
Tom,Patterson,[email protected],1.34,4.02,Ok,,2017-04-27 01:55:12.313799
Sam,Jenkins,[email protected],1.00,0.00,Ok,,2017-07-16 02:34:47.674287
Steve,Stuart,[email protected],1.00,1.00,Ok,,2017-06-12 03:32:00.706554
Maggie,Patterson,[email protected],1.00,2.00,Ok,,2017-05-26 01:23:14.097393
Maggie,Stuart,[email protected],1.00,2.00,Ok,,2017-05-19 23:11:08.624354
Jane,Doe,[email protected],1.00,3.00,Ok,,2017-04-15 19:40:17.044921
Steve,Patterson,[email protected],1.00,3.00,Ok,,2017-04-09 17:14:23.591656
Dave,Smith,[email protected],1.00,3.00,Ok,,2017-04-01 18:35:10.731005
Sam,Wilks,[email protected],1.00,4.00,Ok,,2017-03-01 09:40:56
Kurt,Jefferson,[email protected],1.00,5.00,Ok,,2017-02-24 08:23:05
Sam,Stuart,[email protected],1.00,5.00,Ok,,2017-02-12 00:14:31
Jane,Stuart,[email protected],1.00,5.00,Ok,,2017-02-06 14:52:28
Dave,Davis,[email protected],1.00,0.00,,,2016-11-18 01:37:25
Sam,Patterson,[email protected],1.00,8.00,Ok,,2016-11-01 11:27:17
Tom,Jefferson,[email protected],1.00,10.00,Ok,,2016-09-27 09:56:48
Jane,Stuart,[email protected],1.00,7.00,,,2016-08-09 14:42:25
Maggie,Jefferson,[email protected],1.00,12.00,Ok,,2016-07-26 05:02:16
No Reward,Description: (None for No Reward),,,,,,
Mary,Wilks,[email protected],20.00,60.00,Ok,,2017-04-21 02:44:43.395224
Neil,Patterson,[email protected],10.00,80.00,Ok,,2016-11-12 17:49:37
Corey,Davis,[email protected],6.00,90.00,Ok,,2016-04-01 15:19:52
Steve,Jacobs,[email protected],5.00,21.00,Ok,,2017-01-04 19:38:44
Jane,Jenkins,[email protected],5.00,30.00,Ok,,2017-01-15 17:24:39
John,Jacobs,[email protected],3.14,34.54,Ok,,2016-08-23 16:09:25
Neil,Smith,[email protected],3.00,24.00,Ok,,2016-11-28 02:57:48
Corey,Wilks,[email protected],2.00,8.00,Ok,,2017-03-26 20:13:08.207869
Corey,Smith,[email protected],1.00,0.00,Ok,,2017-07-05 01:50:35.171076
Mary,Patterson,[email protected],1.00,0.00,Ok,,2017-07-04 18:05:23.052059
Jane,Stuart,[email protected],1.00,2.00,Ok,,2017-05-21 19:42:36.098523
Travis,Arnold,[email protected],1.00,3.00,Ok,,2017-04-19 08:04:33.428559
John,Robinson,[email protected],1.00,4.00,Ok,,2017-03-30 14:59:33.850333
Travis,Arnold,[email protected],1.00,6.00,Ok,,2017-01-28 22:02:57
11 changes: 11 additions & 0 deletions random_names.py
Original file line number Diff line number Diff line change
@@ -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}')

0 comments on commit 5f9d635

Please sign in to comment.