This repository has been archived by the owner on Mar 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
/
gen_operator_list.py
72 lines (60 loc) · 3.12 KB
/
gen_operator_list.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
#!/usr/bin/python
# encoding: utf-8
# Copyright (C) 2019-2020 ArvVoid (https://github.com/arvvoid)
# SPDX-License-Identifier: GPL-2.0-or-later
from __future__ import absolute_import, division
# simple utility script to generate provider list for all Hbo Go Eu
# usefull for wiki and documentation and get the
# "big picture" and have a panorama of all operators.
# will generate marked-up list for documentation
import requests
import os.path
import codecs
from datetime import date
from hbogolib.constants import HbogoConstants
def replacetextbetween(original, delimeter_a, delimter_b, newtext):
leadingtext = original.split(delimeter_a)[0]
trailingtext = original.split(delimter_b)[1]
return leadingtext + delimeter_a + newtext + delimter_b + trailingtext
info_string = "|COUNTRY|OPERATOR|LOGIN TYPE|API" + os.linesep
info_string = info_string + "|-------|--------|----------|---|" + os.linesep
print('HBO Go EU Operator list generator V2.0: ')
print('')
print('')
for countrie in HbogoConstants.countries:
if countrie[6] == HbogoConstants.HANDLER_EU:
url_basic = 'https://api.ugw.hbogo.eu/v3.0/Operators/' + str(countrie[3]) + '/JSON/' + str(countrie[4]) + '/COMP'
url_operators = 'https://' + str(countrie[2]) + 'gwapi.hbogo.eu/v2.1/Operators/json/' + str(countrie[3]) + '/COMP'
print('Processing operators for: ' + str(countrie[0]) + '...')
json_web_operators = requests.get(url_basic).json()
for operator in json_web_operators['Items']:
print('DIRECT ' + operator['Type'] + ': ' + operator['Name'])
info_string = info_string + "|" + str(countrie[0]) + "|" + operator['Name'] + "|" + 'DIRECT (' + operator['Type'] + ")|EU|" + os.linesep
json_operators = requests.get(url_operators).json()
for operator in json_operators['Items']:
strtype = "AFFILIATE GATEWAY"
if len(operator['RedirectionUrl']) > 0:
strtype = "AFFILIATE OAuth External (Redirect)"
print(strtype + ': ' + operator['Name'])
info_string = info_string + "|" + str(countrie[0]) + "|" + operator['Name'] + "|" + strtype + "|EU|" + os.linesep
if countrie[6] == HbogoConstants.HANDLER_NORDIC: # or HANDLER_SPAIN (same value)
print('Processing operators for: ' + str(countrie[0]) + '...')
info_string = info_string + "|" + str(countrie[0]) + "|" + "HBO Subscription " + str(countrie[0]) + "|DIRECT|NORDIC/SPAIN|" + os.linesep
print("")
print("Preparing output...")
output = os.linesep + "Last update: " + str(date.today()) + os.linesep + os.linesep + info_string + os.linesep
if os.path.isfile('../hgowiki/Regional-support.md'):
file_r = codecs.open('../hgowiki/Regional-support.md', encoding='utf-8')
original = file_r.read()
file_r.close()
output = replacetextbetween(original, "<!--- BEGIN GENERATED --->", "<!--- END GENERATED --->", output)
file = codecs.open("../hgowiki/Regional-support.md", "w", "utf-8")
file.write(output)
file.close()
print("Done!")
else:
print("operators.md...")
file = codecs.open("operators.md", "w", "utf-8")
file.write(output)
file.close()
print("Done!")