-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuttondown-to-listmonk.py
More file actions
48 lines (39 loc) · 1.73 KB
/
buttondown-to-listmonk.py
File metadata and controls
48 lines (39 loc) · 1.73 KB
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
import csv
import json
# Input: The file you downloaded from Buttondown
input_file = 'buttondown_subscribers.csv'
# Output: The file ready for Listmonk
output_file = 'listmonk_ready.csv'
def migrate():
with open(input_file, mode='r', encoding='utf-8') as infile:
reader = csv.DictReader(infile)
# Prepare the output file
with open(output_file, mode='w', encoding='utf-8', newline='') as outfile:
# Listmonk headers: email, name, attributes
fieldnames = ['email', 'name', 'attributes']
writer = csv.DictWriter(outfile, fieldnames=fieldnames)
writer.writeheader()
count = 0
for row in reader:
# 1. Clean the email
email = row.get('email', '').strip().lower()
if not email:
continue
# 2. Extract Name (If Buttondown has it, otherwise use part of email)
name = row.get('name', '').strip() or email.split('@')[0]
# 3. Handle Attributes (Tags, metadata, etc.)
# We pack these into a JSON string for Listmonk's 'attributes' column
attribs = {
"source": "buttondown_migration",
"tags": row.get('tags', '').split(','),
"subscriber_type": row.get('subscriber_type', 'regular')
}
writer.writerow({
'email': email,
'name': name,
'attributes': json.dumps(attribs)
})
count += 1
print(f"Successfully processed {count} subscribers into {output_file}")
if __name__ == "__main__":
migrate()