2 # -*- coding: utf-8 -*-
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the Revised BSD License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 Revised BSD License for more details.
13 Copyright 2015-2024 Game Maker 2k - https://github.com/GameMaker2k
14 Copyright 2015-2024 Kazuki Przyborowski - https://github.com/KazukiPrzyborowski
16 $FileInfo: example.py - Last Update: 10/17/2024 Ver. 0.9.6 RC 1 - Author: cooldude2k $
19 from __future__
import absolute_import
, division
, print_function
, unicode_literals
, generators
, with_statement
, nested_scopes
25 # Ensure compatibility with both Python 2 and 3
27 reload(sys
) # Only required in Python 2
28 sys
.setdefaultencoding('utf-8')
29 except (NameError, AttributeError):
32 # Function to gather valid directories
33 def get_data_directories():
35 "./data/xml", "./data/xmlalt",
36 "./data/json", "./data/jsonalt",
37 "./data/sql", "./php/data"
39 return [d
for d
in potential_dirs
if os
.path
.isdir(d
)]
41 # Function to process a file based on its extension and load data
42 def process_file(filepath
, extensions
, extensionsc
):
43 fileinfo
= os
.path
.splitext(filepath
)
44 ext
= fileinfo
[1].lower()
45 subext
= os
.path
.splitext(fileinfo
[0])[1].lower() if ext
in extensionsc
else None
47 if ext
in extensions
or subext
in extensions
:
49 sqlitedatatype
= False
51 if ext
== ".xml" or subext
== ".xml":
52 if pyhockeystats
.CheckXMLFile(filepath
):
53 if pyhockeystats
.CheckHockeyXML(filepath
):
54 funcarray
= {'informat': "xml", 'inxmlfile': filepath
}
55 elif pyhockeystats
.CheckHockeySQLiteXML(filepath
):
56 funcarray
= {'informat': "xml", 'inxmlfile': filepath
}
58 elif ext
== ".db3" and pyhockeystats
.CheckSQLiteDatabase(filepath
):
59 funcarray
= {'informat': "database", 'insdbfile': filepath
}
60 elif ext
== ".sql" or subext
== ".sql":
61 funcarray
= {'informat': "sql", 'insqlfile': filepath
}
62 elif ext
== ".json" or subext
== ".json":
63 funcarray
= {'informat': "json", 'injsonfile': filepath
}
68 hockeyarray
= pyhockeystats
.MakeHockeySQLiteArrayFromHockeySQLiteData(funcarray
)
70 hockeyarray
= pyhockeystats
.MakeHockeyArrayFromHockeyData(funcarray
)
72 if pyhockeystats
.CheckHockeySQLiteArray(hockeyarray
):
73 hockeyarray
= pyhockeystats
.MakeHockeyArrayFromHockeySQLiteArray(hockeyarray
)
75 return hockeyarray
if pyhockeystats
.CheckHockeyArray(hockeyarray
) else None
78 # Function to display hockey data
79 def display_hockey_data(hockeyarray
):
80 for hlkey
in hockeyarray
['leaguelist']:
81 for hckey
in hockeyarray
[hlkey
]['conferencelist']:
82 for hdkey
in hockeyarray
[hlkey
][hckey
]['divisionlist']:
83 for htkey
in hockeyarray
[hlkey
][hckey
][hdkey
]['teamlist']:
84 conference
= hockeyarray
[hlkey
].get('conferenceinfo', {}).get('fullname', '')
85 division
= hockeyarray
[hlkey
][hckey
].get('divisioninfo', {}).get('fullname', '')
86 team
= hockeyarray
[hlkey
][hckey
][hdkey
][htkey
]['teaminfo']['fullname']
87 league
= hockeyarray
[hlkey
]['leagueinfo']['fullname']
89 if conference
and division
:
90 print("{league} / {conference} / {division} / {team}".format(
91 league
=league
, conference
=conference
, division
=division
, team
=team
))
93 print("{league} / {conference} / {team}".format(
94 league
=league
, conference
=conference
, team
=team
))
96 print("{league} / {division} / {team}".format(
97 league
=league
, division
=division
, team
=team
))
99 print("{league} / {team}".format(
100 league
=league
, team
=team
))
104 defroot
= get_data_directories()
106 print("No valid data directories found.")
109 rootdir
= sys
.argv
[1] if len(sys
.argv
) > 1 else random
.choice(defroot
)
110 extensions
= pyhockeystats
.extensionswd
111 extensionsc
= pyhockeystats
.outextlistwd
113 if os
.path
.isdir(rootdir
):
114 for subdir
, _
, files
in os
.walk(rootdir
):
116 filepath
= os
.path
.join(subdir
, file)
117 hockeyarray
= process_file(filepath
, extensions
, extensionsc
)
120 print("\n--------------------------------------------------------------------------")
121 print("File: {}".format(filepath
))
122 display_hockey_data(hockeyarray
)
123 print("--------------------------------------------------------------------------\n")
124 elif os
.path
.isfile(rootdir
):
125 hockeyarray
= process_file(rootdir
, extensions
, extensionsc
)
127 print("\n--------------------------------------------------------------------------")
128 print("File: {}".format(rootdir
))
129 display_hockey_data(hockeyarray
)
130 print("--------------------------------------------------------------------------\n")
132 print("Invalid path provided.")
135 if __name__
== "__main__":