-
Notifications
You must be signed in to change notification settings - Fork 5
/
create-specialists-pages.py
43 lines (29 loc) · 1.39 KB
/
create-specialists-pages.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import csv
import re
import shutil
with open('okfn-network-experts.csv', mode = 'r') as file:
csvFile = csv.reader(file)
next(csvFile)
for line in csvFile:
source = 'content/specialist.md'
destination = f'content/specialist/{line[10]}.md'
shutil.copy(source, destination)
# Update metadata from specialist page
specialist_file = open(destination, 'r')
specialist_lines = specialist_file.readlines()
specialist_file = open(destination, 'w')
for i, l in enumerate(specialist_lines):
if 'og_url' in l:
specialist_lines[i] = l.replace('specialist', f'specialist/{line[10]}')
if 'og_image' in l:
specialist_lines[i] = f'og_image: "https://network.okfn.org/images/directory/{line[8]}"\n'
if 'og_title' in l:
title = f'"{line[1]} is part of the Open Knowledge Network"'
specialist_lines[i] = re.sub(r'([\w]*:?) "(.*)".*', r'\1 ' + title, l)
if 'og_description' in l:
description = '"Get in touch with our pool of experts in open data, data literacies, and more."'
specialist_lines[i] = re.sub(r'([\w]*:?) "(.*)".*', r'\1 ' + description, l)
specialist_file.write(''.join(specialist_lines))
specialist_file.close()