Skip to content

Commit 5f9d635

Browse files
committed
Code Examples
1 parent 2165e57 commit 5f9d635

File tree

6 files changed

+191
-0
lines changed

6 files changed

+191
-0
lines changed

Python-CSV/names.csv

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
first_name,last_name,email
2+
3+
Mary,Smith-Robinson,[email protected]
4+
5+
Jane,Stuart,[email protected]
6+
7+
Steve,Robinson,[email protected]
8+
Nicole,Jacobs,[email protected]
9+
Jane,Wright,[email protected]
10+
11+
Kurt,Wright,[email protected]
12+
Kurt,Robinson,[email protected]
13+
Jane,Jenkins,[email protected]
14+
Neil,Robinson,[email protected]
15+
Tom,Patterson,[email protected]
16+
Sam,Jenkins,[email protected]
17+
Steve,Stuart,[email protected]
18+
Maggie,Patterson,[email protected]
19+
Maggie,Stuart,[email protected]
20+
21+
Steve,Patterson,[email protected]
22+
23+
24+
Kurt,Jefferson,[email protected]
25+
26+
Jane,Stuart,[email protected]
27+
28+
Sam,Patterson,[email protected]
29+
Tom,Jefferson,[email protected]
30+
Jane,Stuart,[email protected]
31+
Maggie,Jefferson,[email protected]
32+
33+
Neil,Patterson,[email protected]
34+
Corey,Davis,[email protected]
35+
Steve,Jacobs,[email protected]
36+
Jane,Jenkins,[email protected]
37+
John,Jacobs,[email protected]
38+
39+
Corey,Wilks,[email protected]
40+
Corey,Smith,[email protected]
41+
Mary,Patterson,[email protected]
42+
Jane,Stuart,[email protected]
43+
Travis,Arnold,[email protected]
44+
John,Robinson,[email protected]
45+
Travis,Arnold,[email protected]

Python-CSV/new_names.csv

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
first_name last_name
2+
John Doe
3+
Mary Smith-Robinson
4+
Dave Smith
5+
Jane Stuart
6+
Tom Wright
7+
Steve Robinson
8+
Nicole Jacobs
9+
Jane Wright
10+
Jane Doe
11+
Kurt Wright
12+
Kurt Robinson
13+
Jane Jenkins
14+
Neil Robinson
15+
Tom Patterson
16+
Sam Jenkins
17+
Steve Stuart
18+
Maggie Patterson
19+
Maggie Stuart
20+
Jane Doe
21+
Steve Patterson
22+
Dave Smith
23+
Sam Wilks
24+
Kurt Jefferson
25+
Sam Stuart
26+
Jane Stuart
27+
Dave Davis
28+
Sam Patterson
29+
Tom Jefferson
30+
Jane Stuart
31+
Maggie Jefferson
32+
Mary Wilks
33+
Neil Patterson
34+
Corey Davis
35+
Steve Jacobs
36+
Jane Jenkins
37+
John Jacobs
38+
Neil Smith
39+
Corey Wilks
40+
Corey Smith
41+
Mary Patterson
42+
Jane Stuart
43+
Travis Arnold
44+
John Robinson
45+
Travis Arnold

Python-CSV/parse_csv.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import csv
2+
3+
with open('names.csv', 'r') as csv_file:
4+
csv_reader = csv.DictReader(csv_file)
5+
6+
with open('new_names.csv', 'w') as new_file:
7+
fieldnames = ['first_name', 'last_name']
8+
9+
csv_writer = csv.DictWriter(new_file, fieldnames=fieldnames, delimiter='\t')
10+
11+
csv_writer.writeheader()
12+
13+
for line in csv_reader:
14+
del line['email']
15+
csv_writer.writerow(line)

Python-Patreon-CSV/parse_csv.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import csv
2+
3+
html_output = ''
4+
names = []
5+
6+
with open('patrons.csv', 'r') as data_file:
7+
csv_data = csv.DictReader(data_file)
8+
9+
# We don't want first line of bad data
10+
next(csv_data)
11+
12+
for line in csv_data:
13+
if line['FirstName'] == 'No Reward':
14+
break
15+
names.append(f"{line['FirstName']} {line['LastName']}")
16+
17+
html_output += f'<p>There are currently {len(names)} public contributors. Thank You!</p>'
18+
19+
html_output += '\n<ul>'
20+
21+
for name in names:
22+
html_output += f'\n\t<li>{name}</li>'
23+
24+
html_output += '\n</ul>'
25+
26+
print(html_output)

Python-Patreon-CSV/patrons.csv

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
FirstName,LastName,Email,Pledge,Lifetime,Status,Country,Start
2+
1 + Reward,"Description I will add your name to the contributors page on my website.
3+
4+
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.",,,,,,
5+
John,Doe,[email protected],10.00,20.00,Ok,,2017-05-06 21:28:06.183108
6+
Dave,Smith,[email protected],5.00,10.00,Ok,,2017-05-29 16:13:58.318920
7+
Mary,Jacobs,[email protected],5.00,10.00,Ok,,2017-05-14 07:37:01.074648
8+
Jane,Stuart,[email protected],5.00,25.00,Ok,,2016-12-30 18:12:13
9+
Tom,Wright,[email protected],5.00,15.00,Ok,,2017-04-14 04:02:06.658439
10+
Steve,Robinson,[email protected],5.00,20.00,Ok,,2017-03-17 02:20:14
11+
Nicole,Jacobs,[email protected],5.00,20.00,Ok,,2017-03-12 17:07:29
12+
Jane,Wright,[email protected],5.00,25.00,,,2017-01-14 17:40:06
13+
Jane,Doe,[email protected],2.50,5.00,Ok,,2017-05-14 11:20:50.798440
14+
Kurt,Wright,[email protected],2.00,2.00,Ok,,2017-06-23 21:12:15.662157
15+
Kurt,Robinson,[email protected],2.00,4.00,Ok,,2017-05-03 03:18:54.877885
16+
Jane,Jenkins,[email protected],2.00,8.00,Ok,,2017-03-23 16:37:47.708634
17+
Neil,Robinson,[email protected],1.50,3.00,Ok,,2017-05-26 19:59:51.013984
18+
Tom,Patterson,[email protected],1.34,4.02,Ok,,2017-04-27 01:55:12.313799
19+
Sam,Jenkins,[email protected],1.00,0.00,Ok,,2017-07-16 02:34:47.674287
20+
Steve,Stuart,[email protected],1.00,1.00,Ok,,2017-06-12 03:32:00.706554
21+
Maggie,Patterson,[email protected],1.00,2.00,Ok,,2017-05-26 01:23:14.097393
22+
Maggie,Stuart,[email protected],1.00,2.00,Ok,,2017-05-19 23:11:08.624354
23+
Jane,Doe,[email protected],1.00,3.00,Ok,,2017-04-15 19:40:17.044921
24+
Steve,Patterson,[email protected],1.00,3.00,Ok,,2017-04-09 17:14:23.591656
25+
Dave,Smith,[email protected],1.00,3.00,Ok,,2017-04-01 18:35:10.731005
26+
Sam,Wilks,[email protected],1.00,4.00,Ok,,2017-03-01 09:40:56
27+
Kurt,Jefferson,[email protected],1.00,5.00,Ok,,2017-02-24 08:23:05
28+
Sam,Stuart,[email protected],1.00,5.00,Ok,,2017-02-12 00:14:31
29+
Jane,Stuart,[email protected],1.00,5.00,Ok,,2017-02-06 14:52:28
30+
Dave,Davis,[email protected],1.00,0.00,,,2016-11-18 01:37:25
31+
Sam,Patterson,[email protected],1.00,8.00,Ok,,2016-11-01 11:27:17
32+
Tom,Jefferson,[email protected],1.00,10.00,Ok,,2016-09-27 09:56:48
33+
Jane,Stuart,[email protected],1.00,7.00,,,2016-08-09 14:42:25
34+
Maggie,Jefferson,[email protected],1.00,12.00,Ok,,2016-07-26 05:02:16
35+
No Reward,Description: (None for No Reward),,,,,,
36+
Mary,Wilks,[email protected],20.00,60.00,Ok,,2017-04-21 02:44:43.395224
37+
Neil,Patterson,[email protected],10.00,80.00,Ok,,2016-11-12 17:49:37
38+
Corey,Davis,[email protected],6.00,90.00,Ok,,2016-04-01 15:19:52
39+
Steve,Jacobs,[email protected],5.00,21.00,Ok,,2017-01-04 19:38:44
40+
Jane,Jenkins,[email protected],5.00,30.00,Ok,,2017-01-15 17:24:39
41+
John,Jacobs,[email protected],3.14,34.54,Ok,,2016-08-23 16:09:25
42+
Neil,Smith,[email protected],3.00,24.00,Ok,,2016-11-28 02:57:48
43+
Corey,Wilks,[email protected],2.00,8.00,Ok,,2017-03-26 20:13:08.207869
44+
Corey,Smith,[email protected],1.00,0.00,Ok,,2017-07-05 01:50:35.171076
45+
Mary,Patterson,[email protected],1.00,0.00,Ok,,2017-07-04 18:05:23.052059
46+
Jane,Stuart,[email protected],1.00,2.00,Ok,,2017-05-21 19:42:36.098523
47+
Travis,Arnold,[email protected],1.00,3.00,Ok,,2017-04-19 08:04:33.428559
48+
John,Robinson,[email protected],1.00,4.00,Ok,,2017-03-30 14:59:33.850333
49+
Travis,Arnold,[email protected],1.00,6.00,Ok,,2017-01-28 22:02:57

random_names.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
''' Super simple module to get basic random names and emails'''
2+
import random
3+
4+
random_first = ['John', 'Jane', 'Corey', 'Travis', 'Dave', 'Kurt', 'Neil', 'Sam', 'Mary', 'Maggie', 'Nicole', 'Steve', 'Tom']
5+
random_last = ['Smith', 'Doe', 'Jenkins', 'Robinson', 'Davis', 'Stuart', 'Jefferson', 'Jacobs', 'Wright', 'Patterson', 'Wilks', 'Arnold']
6+
7+
for num in range(20):
8+
first = random.choice(random_first)
9+
last = random.choice(random_last)
10+
email = first.lower() + last.lower() + '@bogusemail.com'
11+
print(f'{first} {last} - {email}')

0 commit comments

Comments
 (0)