-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_headers.py
67 lines (42 loc) · 1.36 KB
/
csv_headers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from pandas.io.clipboard import clipboard_get
import subprocess
from datetime import date, datetime
# from pynput.keyboard import Key, Controller
d = datetime.now()
date = d.strftime('%Y%m%d-%H%M%S')
def write_to_clipboard(output):
process = subprocess.Popen(
'pbcopy', env={'LANG': 'en_US.UTF-8'}, stdin=subprocess.PIPE)
process.communicate(output.encode('utf-8'))
file_path = clipboard_get()
import csv
csv_file = file_path
count_row_csv = 0
count_column = -1
print()
print()
with open(csv_file, 'r', newline='', encoding='UTF-8') as h:
reader = csv.reader(h, delimiter=",")
data = list(reader)
for row in data:
count_row_csv += 1
if count_row_csv == 1:
for col in row:
count_column += 1
name = col.lower()
if name == 'last name':
name = 'last'
if name == 'first name':
name = 'first'
if name == 'email address':
name = 'email'
if name == 'job title':
name = 'title'
name = name.replace(' ', '_')
print(f"{name} = row[{count_column}]")
print(f"\n\n^^^^ COPY ABOVE ^^^^\n\n")
# output = f"{output}\n\n{print_string}"
# write_to_clipboard(output)
# print(f'\nOutput copied to clipboard')
print()
###