-
Notifications
You must be signed in to change notification settings - Fork 2
/
tga-db2.py
132 lines (116 loc) · 4.44 KB
/
tga-db2.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Exploring the Training.gov.au Web Services
# Author: Marcus Wynwood (@MarcusTeachUs)
#
# Finds EVERY training pack, EVERY qual and EVERY unit and puts it in a SQLite Database.
# Units are duplicated if they exist in multiple quals.
# It's not normalised of efficient... yet!
# It takes a couple of hours to run too.
#
# I don't think it's quite complete, and bugs out on line 92 after about 2 hours.
# tga-db2.py", line 92, in <module>
# for units in r.UnitGrid.UnitGridEntry:
# AttributeError: 'NoneType' object has no attribute 'UnitGridEntry'
#
# Explore tga-db2.db with SQLiteStudio or something to see what this code generates.
#
# It would be nice to also store what Stream the elective units belong to.
# Then it could take into account Packaging Rules.
# Lots more to do, but this is a start.
import zeep
from zeep.wsse.username import UsernameToken
import sqlite3
wsdl = 'https://ws.sandbox.training.gov.au/Deewr.Tga.Webservices/TrainingComponentServiceV7.svc?wsdl'
username = "WebService.Read"
password = "Asdf098"
client = zeep.Client(wsdl=wsdl, wsse=UsernameToken(username, password))
db = sqlite3.connect('tga-db2.db')
cursor = db.cursor()
cursor.execute('''
CREATE TABLE trainingpacks(
id INTEGER PRIMARY KEY,
code TEXT,
title TEXT)
''')
cursor.execute('''
CREATE TABLE quals(
id INTEGER PRIMARY KEY,
code TEXT,
title TEXT,
type TEXT,
trainingpack TEXT)
''')
cursor.execute('''
CREATE TABLE units(
id INTEGER PRIMARY KEY,
code TEXT,
title TEXT,
core TEXT,
qual TEXT
)''')
db.commit()
TrainingComponentTypeFilter = {
"IncludeAccreditedCourse": False,
"IncludeAccreditedCourseModule": False,
"IncludeQualification": True,
"IncludeSkillSet": True,
"IncludeTrainingPackage": True,
"IncludeUnit": False,
"IncludeUnitContextualisation": False
}
# Create a TrainingComponentSearchRequest for the search
TrainingComponentSearchRequest = {
"ClassificationFilters": "",
"Filter": "", # The search term.
"IncludeDeleted": False,
"IncludeSuperseeded": False,
# "PageNumber": 0,
# "PageSize": 0,
"SearchCode": True,
"SearchIndustrySector": False,
"SearchOccupation": False,
"SearchTitle": False,
"TaxonomyOccupationFilter": "",
"TaxonomyIndustrySectorFilter": "",
"TrainingComponentTypes": TrainingComponentTypeFilter,
"IncludeLegacyData": False
}
TrainingComponentSearchResult = client.service.Search(TrainingComponentSearchRequest)
# print(TrainingComponentSearchResult)
for tp in TrainingComponentSearchResult.Results.TrainingComponentSummary:
if (tp.ComponentType[0] == 'Qualification' or tp.ComponentType[0] == 'SkillSet') and tp.IsCurrent == True:
# I've just used the first 3 letters of the qual as the trainingpack. Bit dodgy, but probably accurate
cursor.execute('''INSERT INTO quals(code, title, type, trainingpack) VALUES(?,?,?,?)''', (tp.Code, tp.Title, tp.ComponentType[0], str(tp.Code)[:3]))
db.commit()
# Loop to grab all units in qual?
TrainingComponentSearchRequest_qual = {
"ClassificationFilters": "",
"Filter": tp.Code,
"IncludeDeleted": False,
"IncludeSuperseeded": False,
"SearchCode": True,
"SearchIndustrySector": False,
"SearchOccupation": False,
"SearchTitle": False,
"IncludeLegacyData": False
}
TrainingComponentSearchResult_qual = client.service.Search(TrainingComponentSearchRequest_qual)
TrainingComponent_qual = client.service.GetDetails(TrainingComponentSearchResult_qual.Results.TrainingComponentSummary)
for r in TrainingComponent_qual.Releases.Release:
if r.Currency == 'Current':
for units in r.UnitGrid.UnitGridEntry:
cursor.execute('''INSERT INTO units(code, title, core, qual) VALUES(?,?,?,?)''', (units.Code, units.Title, units.IsEssential, tp.Code))
db.commit()
if tp.ComponentType[0] == 'TrainingPackage' and tp.IsCurrent == True:
cursor.execute('''INSERT INTO trainingpacks(code, title) VALUES(?,?)''', (tp.Code, tp.Title))
db.commit()
db.commit() # for luck
# cursor.execute('''SELECT * FROM trainingpacks''')
# for row in cursor:
# print(row)
# cursor.execute('''SELECT * FROM quals''')
# for row in cursor:
# print(row)
# cursor.execute('''SELECT * FROM quals WHERE trainingpack="ICT" AND type="Qualification"''')
# for row in cursor:
# print(row)
db.close()