Commit 7b34b784 authored by Daniel W Bond's avatar Daniel W Bond
Browse files

added slugs to major models

parent 3adc9290
# standard library imports # standard library imports
import re import re
import random
import string
# third party imports # third party imports
import requests import requests
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
# from stackoverflow https://stackoverflow.com/questions/2257441/
def slug_generator(size=6, chars=string.ascii_letters + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
try: try:
page = requests.get('http://catalog.gmu.edu/content.php?catoid=25&navoid=4959') page = requests.get('http://catalog.gmu.edu/content.php?catoid=25&navoid=4959')
page.raise_for_status() page.raise_for_status()
...@@ -30,12 +36,14 @@ else: ...@@ -30,12 +36,14 @@ else:
# the last item is an edge case the way the brackets work # the last item is an edge case the way the brackets work
for place in range(len(program_names)-1): for place in range(len(program_names)-1):
fixtures.write(' "fields": {\n "name": "' + program_names[place] + '"\n') fixtures.write(' "fields": {\n "name": "' + program_names[place] + '",\n')
fixtures.write(' "slug": "' + slug_generator() + '"\n')
fixtures.write(' },\n "model": "accounts.major",\n') fixtures.write(' },\n "model": "accounts.major",\n')
fixtures.write(' "pk": ' + str(place + 1) + '\n}, {\n') fixtures.write(' "pk": ' + str(place + 1) + '\n}, {\n')
# the last item in the list # the last item in the list
fixtures.write(' "fields": {\n "name": "' + program_names[-1] + '"\n') fixtures.write(' "fields": {\n "name": "' + program_names[-1] + '",\n')
fixtures.write(' "slug": "' + slug_generator() + '"\n')
fixtures.write(' },\n "model": "accounts.major",\n') fixtures.write(' },\n "model": "accounts.major",\n')
fixtures.write(' "pk": ' + str(len(program_names)) + '\n') fixtures.write(' "pk": ' + str(len(program_names)) + '\n')
......
[{ [{
"fields": { "fields": {
"name": "Accounting, BS" "name": "Accounting, BS",
"slug": "3Ojvqb"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 1 "pk": 1
}, { }, {
"fields": { "fields": {
"name": "Anthropology, BA" "name": "Anthropology, BA",
"slug": "ICOAZD"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 2 "pk": 2
}, { }, {
"fields": { "fields": {
"name": "Applied Computer Science, BS" "name": "Applied Computer Science, BS",
"slug": "h3Avvg"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 3 "pk": 3
}, { }, {
"fields": { "fields": {
"name": "Applied Information Technology, BS" "name": "Applied Information Technology, BS",
"slug": "BvOIfT"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 4 "pk": 4
}, { }, {
"fields": { "fields": {
"name": "Applied Science, BAS" "name": "Applied Science, BAS",
"slug": "CD9ZvL"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 5 "pk": 5
}, { }, {
"fields": { "fields": {
"name": "Art and Visual Technology, BA" "name": "Art and Visual Technology, BA",
"slug": "DJcPIU"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 6 "pk": 6
}, { }, {
"fields": { "fields": {
"name": "Art and Visual Technology, BFA" "name": "Art and Visual Technology, BFA",
"slug": "2Vcqh0"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 7 "pk": 7
}, { }, {
"fields": { "fields": {
"name": "Art History, BA" "name": "Art History, BA",
"slug": "uQlpMT"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 8 "pk": 8
}, { }, {
"fields": { "fields": {
"name": "Astronomy, BS" "name": "Astronomy, BS",
"slug": "53iV6H"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 9 "pk": 9
}, { }, {
"fields": { "fields": {
"name": "Athletic Training, BS" "name": "Athletic Training, BS",
"slug": "Ezl2Pt"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 10 "pk": 10
}, { }, {
"fields": { "fields": {
"name": "Bioengineering, BS" "name": "Bioengineering, BS",
"slug": "8qooXn"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 11 "pk": 11
}, { }, {
"fields": { "fields": {
"name": "Biology, BA" "name": "Biology, BA",
"slug": "HUg2V7"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 12 "pk": 12
}, { }, {
"fields": { "fields": {
"name": "Biology, BS" "name": "Biology, BS",
"slug": "g7lRg8"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 13 "pk": 13
}, { }, {
"fields": { "fields": {
"name": "Business Administration, MBA" "name": "Business Administration, MBA",
"slug": "wtPyVa"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 14 "pk": 14
}, { }, {
"fields": { "fields": {
"name": "Chemistry, BA" "name": "Chemistry, BA",
"slug": "JSzv6K"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 15 "pk": 15
}, { }, {
"fields": { "fields": {
"name": "Chemistry, BS" "name": "Chemistry, BS",
"slug": "rVhDX1"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 16 "pk": 16
}, { }, {
"fields": { "fields": {
"name": "Civil and Infrastructure Engineering, BS" "name": "Civil and Infrastructure Engineering, BS",
"slug": "YmGwjE"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 17 "pk": 17
}, { }, {
"fields": { "fields": {
"name": "Communication, BA" "name": "Communication, BA",
"slug": "yzHRO4"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 18 "pk": 18
}, { }, {
"fields": { "fields": {
"name": "Community Health, BS" "name": "Community Health, BS",
"slug": "tAVHya"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 19 "pk": 19
}, { }, {
"fields": { "fields": {
"name": "Computer Engineering, BS" "name": "Computer Engineering, BS",
"slug": "DibaB0"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 20 "pk": 20
}, { }, {
"fields": { "fields": {
"name": "Computer Game Design, BFA" "name": "Computer Game Design, BFA",
"slug": "76BLn2"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 21 "pk": 21
}, { }, {
"fields": { "fields": {
"name": "Computer Science, BS" "name": "Computer Science, BS",
"slug": "R5H7ZR"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 22 "pk": 22
}, { }, {
"fields": { "fields": {
"name": "Conflict Analysis and Resolution, BA" "name": "Conflict Analysis and Resolution, BA",
"slug": "RD5tZ6"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 23 "pk": 23
}, { }, {
"fields": { "fields": {
"name": "Conflict Analysis and Resolution, BS" "name": "Conflict Analysis and Resolution, BS",
"slug": "K0gaQi"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 24 "pk": 24
}, { }, {
"fields": { "fields": {
"name": "Creative Writing, BFA" "name": "Creative Writing, BFA",
"slug": "49RqIR"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 25 "pk": 25
}, { }, {
"fields": { "fields": {
"name": "Criminology, Law and Society, BA" "name": "Criminology, Law and Society, BA",
"slug": "fakWkr"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 26 "pk": 26
}, { }, {
"fields": { "fields": {
"name": "Criminology, Law and Society, BS" "name": "Criminology, Law and Society, BS",
"slug": "kzvy90"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 27 "pk": 27
}, { }, {
"fields": { "fields": {
"name": "Dance, BA" "name": "Dance, BA",
"slug": "RHc32j"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 28 "pk": 28
}, { }, {
"fields": { "fields": {
"name": "Dance, BFA" "name": "Dance, BFA",
"slug": "azV9UO"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 29 "pk": 29
}, { }, {
"fields": { "fields": {
"name": "Earth Science, BS" "name": "Earth Science, BS",
"slug": "UazNq5"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 30 "pk": 30
}, { }, {
"fields": { "fields": {
"name": "Economics, BA" "name": "Economics, BA",
"slug": "8TZgnb"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 31 "pk": 31
}, { }, {
"fields": { "fields": {
"name": "Economics, BS" "name": "Economics, BS",
"slug": "Pmhjsw"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 32 "pk": 32
}, { }, {
"fields": { "fields": {
"name": "Electrical Engineering, BS" "name": "Electrical Engineering, BS",
"slug": "SXf9qN"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 33 "pk": 33
}, { }, {
"fields": { "fields": {
"name": "English, BA" "name": "English, BA",
"slug": "nXLnuM"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 34 "pk": 34
}, { }, {
"fields": { "fields": {
"name": "Environmental and Sustainability Studies, BA" "name": "Environmental and Sustainability Studies, BA",
"slug": "gxRb1A"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 35 "pk": 35
}, { }, {
"fields": { "fields": {
"name": "Environmental Science, BS" "name": "Environmental Science, BS",
"slug": "2pjQ5F"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 36 "pk": 36
}, { }, {
"fields": { "fields": {
"name": "Executive MBA" "name": "Executive MBA",
"slug": "Rl8GrX"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 37 "pk": 37
}, { }, {
"fields": { "fields": {
"name": "Film and Video Studies, BA" "name": "Film and Video Studies, BA",
"slug": "Olv1nj"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 38 "pk": 38
}, { }, {
"fields": { "fields": {
"name": "Finance, BS" "name": "Finance, BS",
"slug": "jMm31Y"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 39 "pk": 39
}, { }, {
"fields": { "fields": {
"name": "Foreign Languages, BA" "name": "Foreign Languages, BA",
"slug": "XSmNtX"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 40 "pk": 40
}, { }, {
"fields": { "fields": {
"name": "Forensic Science, BS" "name": "Forensic Science, BS",
"slug": "mwWUg4"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 41 "pk": 41
}, { }, {
"fields": { "fields": {
"name": "Geography, BA" "name": "Geography, BA",
"slug": "5wfT8v"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 42 "pk": 42
}, { }, {
"fields": { "fields": {
"name": "Geography, BS" "name": "Geography, BS",
"slug": "UGFpPU"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 43 "pk": 43
}, { }, {
"fields": { "fields": {
"name": "Geology, BA" "name": "Geology, BA",
"slug": "hxK6hS"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 44 "pk": 44
}, { }, {
"fields": { "fields": {
"name": "Global Affairs, BA" "name": "Global Affairs, BA",
"slug": "MqJKF9"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 45 "pk": 45
}, { }, {
"fields": { "fields": {
"name": "Global and Environmental Change, BS" "name": "Global and Environmental Change, BS",
"slug": "c7Xv2j"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 46 "pk": 46
}, { }, {
"fields": { "fields": {
"name": "Government and International Politics, BA" "name": "Government and International Politics, BA",
"slug": "1XCKnm"
}, },
"model": "accounts.major", "model": "accounts.major",
"pk": 47 "pk": 47
}, { }, {
"fields": { "fields": {
"name": "Health Administration, BS" "name": "Health Administration, BS",