forked from Torrib/gradestats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename.py
31 lines (23 loc) · 768 Bytes
/
rename.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
# -*- coding: utf-8 -*-
import os
import django
import json
import requests
from grades.models import Course
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gradestats.settings")
django.setup()
base_url = "http://www.ime.ntnu.no/api/course/"
courses = Course.objects.all()
print("Renaming....")
for course in courses:
resp = requests.get(base_url + course.code)
if not resp:
continue
data = json.loads(resp.text)
if not data["course"]:
continue
print("Checking " + course.code)
if data["course"]["norwegianName"] != course.norwegian_name:
print("Renaming " + course.norwegian_name + " to " + data["course"]["norwegianName"])
course.norwegian_name = data["course"]["norwegianName"]
course.save()