forked from gateway4labs/labmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculate_migrations_apr_2019_3rd.py
91 lines (72 loc) · 2.71 KB
/
calculate_migrations_apr_2019_3rd.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from __future__ import print_function
import os
import json
import datetime
import urlparse
import requests
from flask import url_for
from labmanager import app
from labmanager.db import db
from labmanager.models import EmbedApplication, EmbedApplicationTranslation, HttpsUnsupportedUrl, UseLog
from labmanager.rlms import find_smartgateway_html_link
app.config['SERVER_NAME'] = 'gateway.golabz.eu'
app.config['PREFERRED_URL_SCHEME'] = 'https'
with app.app_context():
# if os.path.exists('golabz.json'):
# golabz_labs = json.load(open('golabz.json'))
# else:
if True:
golabz_labs = requests.get("https://www.golabz.eu/rest/labs/retrieve.json").json()
open('golabz.json', 'w').write(json.dumps(golabz_labs, indent=4))
golabz_changes = [
# {
# "id": "99",
# "add": [
# {
# 'app_url': '...',
# 'app_title': '...',
# 'app_format': 'html'
# }
# ],
# 'delete': [
# {
# 'app_url': '...'
# }
# ]
# }
]
for golab_lab in golabz_labs:
for golab_lab_app in golab_lab['lab_apps']:
golabz_url = golab_lab_app['app_url']
url_parsed = urlparse.urlparse(golabz_url)
if url_parsed.netloc != 'gateway.golabz.eu':
continue
if url_parsed.path.endswith('.xml'):
# If it is in Graasp, replace it
golab_lab_id = golab_lab['id']
existing_record = None
for record in golabz_changes:
if record['id'] == golab_lab_id:
existing_record = record
break
if existing_record is None:
existing_record = {
'id': golab_lab_id,
'add': [],
'delete': [],
}
golabz_changes.append(existing_record)
replaced_url = golabz_url
new_url = golabz_url
if new_url.startswith('http://'):
new_url = new_url.replace('http://', 'https://', 1)
new_url = new_url[::-1].replace('.xml'[::-1], '.html'[::-1], 1)[::-1]
existing_record['add'].append({
'app_url': new_url,
'app_title': golab_lab_app['app_title'],
'app_format': 'html',
})
existing_record['delete'].append({
'app_url': replaced_url,
})
open('migration_apr_2019/golabz_replacements_3rd.json', 'w').write(json.dumps(golabz_changes, indent=4))