Skip to content

Commit

Permalink
feat: Add proxy country to daily miniTB standings
Browse files Browse the repository at this point in the history
  • Loading branch information
matluca committed Oct 24, 2023
1 parent a75f26a commit 6a3ca32
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 57 deletions.
84 changes: 42 additions & 42 deletions .firebase/hosting.YnVpbGQvd2Vi.cache
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
favicon.ico,1697179497830,37c3f99abc06a97e255e4c9ba2983eec03a26ebe7bcf89867ac2eb2f2592efa1
favicon.ico,1698136351193,37c3f99abc06a97e255e4c9ba2983eec03a26ebe7bcf89867ac2eb2f2592efa1
flutter.js,1680948331276,97ed2f98cb0c00158de183673e81b516e92e0b04e5b2a9b34b5c424627e8aa48
flutter_service_worker.js,1697179498486,90ec173ed62b5a41777d788cc9ff5ac507fa049546b86f7c9d3414a868a8acdb
index.html,1697179497834,c5def33ef2d9a296bbed86b72fad46ef84c0202990326909e0532a68c995672a
main.dart.js,1697179497726,cdbf655d6797516b3f573034236202604dbc965ee8e603f6a3b32054a1768460
manifest.json,1697179497830,0069eac90b4941b6d15cdb5cea2d9dd3edcbac51469e991f384f14d085aef086
version.json,1697179497730,42e4b6a3c96c25fe6dde6c8cf0eb0a718e946192d913c03b90182fc487ee339d
assets/AssetManifest.json,1697179497826,0c64d61b5aac3e7d9b28f6a8f8e1dd55fc3ba053c60b257bc10b59e5872bb71a
assets/FontManifest.json,1697179497826,bd7e98625fb31537dee7ae98804a62bce7e94d8d345d1b2457badec4826b3cf9
assets/NOTICES,1697179497826,fe53e70a875f129324588dfb090181054812cd885683c32f7fad625bf30801fc
assets/assets/albo.png,1697179497818,2d50fdb5b90314eb1cdf857b2d31305433dd01a5c996159ada59c7fb5b8d680b
assets/assets/ale.jpg,1697179497818,6b5355236fc415402e3ff787cc95813195a105f381e787a7f082eb602992c4c8
assets/assets/enrico.jpg,1697179497818,3c96066caf4432b53e70765696dfdef10f64703310f5255bdf547b4b47e7d111
assets/assets/fabio.jpg,1697179497818,26baa245edaf7e992afbde6c242783748b08f9b2e2846073ca0712118d0475ef
assets/assets/gianluca.jpg,1697179497818,f189ca9c91ba682b3023f16895c6424ce29047404fe096e8b0a4ae31f99ab221
assets/assets/ic_launcher.png,1697179497818,b9e77048465064c8d7099c315d3e7e196ebb7c98ed00408cbdd8af6c6d11221e
assets/assets/launcher.png,1697179497818,4895b14db3b8d8173c817c2d800cc2e6a08999427d2138676577d97c24c1f232
assets/assets/luca.jpg,1697179497818,0d5b8b25b6d0a6bb17ca6b93aab31919729a1732693fbd5398cafa2dae9b068d
assets/assets/melo.jpg,1697179497818,fc89bf42a9d8ccab76eae897e42aec9ada6804519b59ad3d28ef4160689cb31a
assets/assets/naismith.jpg,1697179497818,8f79e011b23b5c3b9ff7006a2117c8b3da99ded7ecc53ded2a762181ee8de3ad
assets/assets/nba.jpg,1697179497818,757a3cd1e17c6c6d6538bcf1c4022a79b7f7af36a609bc09404ff8e0fcbcca16
assets/assets/nic.jpg,1697179497818,976a10d4ded42f467aba2facb79dd734f1640e839289963c31ee3ae3bc310124
assets/assets/podium.png,1697179497818,024313723cfd8555b75bb3413208e6cb22f25e7969cc57c4625b2a8cbe92ddca
assets/assets/profile2017.jpg,1697179497818,97f646f6ec123705471da40ae17bd16120544fa16b61d832112e9dbab7c9ef78
assets/assets/profile2018.jpg,1697179497818,6874279f98021ece85f06469530e40f618a3fb0e0e3408b0626d22ad0cf37f68
assets/assets/profile2019.jpg,1697179497818,aad2cdb74e8e690969d556d689b3e26569726cb142eb92bf0d3d9a12131df0d8
assets/assets/profile2020-bis.jpg,1697179497818,2d19758003da42ddb8607d1a962e1fa10557ed0e2a313f0b1dadafd677511549
assets/assets/profile2020.jpg,1697179497818,d622bb77021716b8cdc880e70679a096cd63facaca8d14c8255ae2a8c5221c97
assets/assets/profile2021.jpg,1697179497818,fe8beae3886f1465591d3cb3edef5b8aa84f61b814724a5fbdeca10c745fcff6
assets/assets/profile2022.jpg,1697179497818,8e7671946557e0395afc06bda6e3564b6bc5119d52760f9fb7f9819896c69902
assets/assets/profile2023.png,1697179497818,d4a5027fe11f1c4fd31645b75a5c62eff2f5d0e02efc314d53412ea6df22f881
assets/assets/pwd.txt,1697179497818,e07f81c57e1895adf720f65ce3d5719cfb18de7bbc300860d01b8e749042f8d6
assets/assets/teo.jpg,1697179497818,ce8baf5b2794f1817fbc9eaa5f1559d22482c8a9e7936ff8ce78b72225fc19fa
assets/assets/thatsnottrue.jpeg,1697179497818,ce20ccc219e5f7f1d5c0ac90f419cf4f3fd2cc4f7c9e50ac56b1a698f7d57609
assets/assets/wethebasce.jpeg,1697179497818,a9c97d6c9291973d50744a3eb8e43dab471eb1fb3cfc871f3202911c263d4a60
assets/assets/yiwei.jpg,1697179497818,c2d7414ffdd6aaae595b8695231f3655e7794bc37ce0e186d520bb62c9db8557
assets/fonts/MaterialIcons-Regular.otf,1697179497822,01e1893e23bcf2e77aa3229c67ae0f47bca9354102373c6363dea40d78fb848c
assets/packages/cupertino_icons/assets/CupertinoIcons.ttf,1697179497822,a77c8ca7f82c41df974e64528dfac4de5332a92a90dd861a44d5619a74b73b2e
assets/packages/material_design_icons_flutter/lib/fonts/materialdesignicons-webfont.ttf,1697179497822,64ecba04fa396c2679b95d836d901f94039b29872886a45d752c3e7368079894
flutter_service_worker.js,1698136351973,cb88e9b3fda324353f9e5cff6ed6bbdda46a273fdd1a830664044e28681e8fee
index.html,1698136351193,4cc2fa3fb08b3d5633ddcd4b2db365c1422442bb0686dd8eb992010900eddcd1
main.dart.js,1698136351069,800bd87080e489f80637a9ea7ae2b0d2db22ca18767ae33ed169f78c413aa8e6
manifest.json,1698136351193,0069eac90b4941b6d15cdb5cea2d9dd3edcbac51469e991f384f14d085aef086
version.json,1698136351073,42e4b6a3c96c25fe6dde6c8cf0eb0a718e946192d913c03b90182fc487ee339d
assets/AssetManifest.json,1698136351185,0c64d61b5aac3e7d9b28f6a8f8e1dd55fc3ba053c60b257bc10b59e5872bb71a
assets/FontManifest.json,1698136351185,bd7e98625fb31537dee7ae98804a62bce7e94d8d345d1b2457badec4826b3cf9
assets/NOTICES,1698136351185,fe53e70a875f129324588dfb090181054812cd885683c32f7fad625bf30801fc
assets/assets/albo.png,1698136351181,2d50fdb5b90314eb1cdf857b2d31305433dd01a5c996159ada59c7fb5b8d680b
assets/assets/ale.jpg,1698136351177,6b5355236fc415402e3ff787cc95813195a105f381e787a7f082eb602992c4c8
assets/assets/enrico.jpg,1698136351177,3c96066caf4432b53e70765696dfdef10f64703310f5255bdf547b4b47e7d111
assets/assets/fabio.jpg,1698136351181,26baa245edaf7e992afbde6c242783748b08f9b2e2846073ca0712118d0475ef
assets/assets/gianluca.jpg,1698136351181,f189ca9c91ba682b3023f16895c6424ce29047404fe096e8b0a4ae31f99ab221
assets/assets/ic_launcher.png,1698136351177,b9e77048465064c8d7099c315d3e7e196ebb7c98ed00408cbdd8af6c6d11221e
assets/assets/launcher.png,1698136351181,4895b14db3b8d8173c817c2d800cc2e6a08999427d2138676577d97c24c1f232
assets/assets/luca.jpg,1698136351177,0d5b8b25b6d0a6bb17ca6b93aab31919729a1732693fbd5398cafa2dae9b068d
assets/assets/melo.jpg,1698136351177,fc89bf42a9d8ccab76eae897e42aec9ada6804519b59ad3d28ef4160689cb31a
assets/assets/naismith.jpg,1698136351181,8f79e011b23b5c3b9ff7006a2117c8b3da99ded7ecc53ded2a762181ee8de3ad
assets/assets/nba.jpg,1698136351177,757a3cd1e17c6c6d6538bcf1c4022a79b7f7af36a609bc09404ff8e0fcbcca16
assets/assets/nic.jpg,1698136351181,976a10d4ded42f467aba2facb79dd734f1640e839289963c31ee3ae3bc310124
assets/assets/podium.png,1698136351181,024313723cfd8555b75bb3413208e6cb22f25e7969cc57c4625b2a8cbe92ddca
assets/assets/profile2017.jpg,1698136351177,97f646f6ec123705471da40ae17bd16120544fa16b61d832112e9dbab7c9ef78
assets/assets/profile2018.jpg,1698136351177,6874279f98021ece85f06469530e40f618a3fb0e0e3408b0626d22ad0cf37f68
assets/assets/profile2019.jpg,1698136351181,aad2cdb74e8e690969d556d689b3e26569726cb142eb92bf0d3d9a12131df0d8
assets/assets/profile2020-bis.jpg,1698136351181,2d19758003da42ddb8607d1a962e1fa10557ed0e2a313f0b1dadafd677511549
assets/assets/profile2020.jpg,1698136351181,d622bb77021716b8cdc880e70679a096cd63facaca8d14c8255ae2a8c5221c97
assets/assets/profile2021.jpg,1698136351177,fe8beae3886f1465591d3cb3edef5b8aa84f61b814724a5fbdeca10c745fcff6
assets/assets/profile2022.jpg,1698136351177,8e7671946557e0395afc06bda6e3564b6bc5119d52760f9fb7f9819896c69902
assets/assets/profile2023.png,1698136351181,d4a5027fe11f1c4fd31645b75a5c62eff2f5d0e02efc314d53412ea6df22f881
assets/assets/pwd.txt,1698136351177,e07f81c57e1895adf720f65ce3d5719cfb18de7bbc300860d01b8e749042f8d6
assets/assets/teo.jpg,1698136351177,ce8baf5b2794f1817fbc9eaa5f1559d22482c8a9e7936ff8ce78b72225fc19fa
assets/assets/thatsnottrue.jpeg,1698136351177,ce20ccc219e5f7f1d5c0ac90f419cf4f3fd2cc4f7c9e50ac56b1a698f7d57609
assets/assets/wethebasce.jpeg,1698136351177,a9c97d6c9291973d50744a3eb8e43dab471eb1fb3cfc871f3202911c263d4a60
assets/assets/yiwei.jpg,1698136351181,c2d7414ffdd6aaae595b8695231f3655e7794bc37ce0e186d520bb62c9db8557
assets/fonts/MaterialIcons-Regular.otf,1698136351185,01e1893e23bcf2e77aa3229c67ae0f47bca9354102373c6363dea40d78fb848c
assets/packages/cupertino_icons/assets/CupertinoIcons.ttf,1698136351181,a77c8ca7f82c41df974e64528dfac4de5332a92a90dd861a44d5619a74b73b2e
assets/packages/material_design_icons_flutter/lib/fonts/materialdesignicons-webfont.ttf,1698136351181,64ecba04fa396c2679b95d836d901f94039b29872886a45d752c3e7368079894
canvaskit/canvaskit.js,1680948331268,862fbc90b0cdab302519d536322dddbcf3c9d519db25260ff9c3d04932747002
canvaskit/canvaskit.wasm,1680948331276,c113b3200832c9cd19033de4cc79770e0bbc8cbd3d09df1a3dec9a513eda0577
canvaskit/profiling/canvaskit.js,1680948331248,5e094643fdde460eef4aefb7fac175854a74ba1ecb1c8652c24145d23122b58f
canvaskit/profiling/canvaskit.wasm,1680948331264,4102b5e3159b137ccc8d739bce1796d9dc795c604e400ae060f30207a01ebe9a
icons/Icon-192.png,1697179497826,419e7818942c0c2a41b5744cd473f10a1d66278d2248c470dedac217d2f7cc0a
icons/Icon-512.png,1697179497830,a326e3b122e46588bbb8e9d8c283ea13ef01ac5368c43df363ebaa805f1d5656
icons/Icon-maskable-192.png,1697179497826,419e7818942c0c2a41b5744cd473f10a1d66278d2248c470dedac217d2f7cc0a
icons/Icon-maskable-512.png,1697179497826,a326e3b122e46588bbb8e9d8c283ea13ef01ac5368c43df363ebaa805f1d5656
icons/Icon-192.png,1698136351189,419e7818942c0c2a41b5744cd473f10a1d66278d2248c470dedac217d2f7cc0a
icons/Icon-512.png,1698136351189,a326e3b122e46588bbb8e9d8c283ea13ef01ac5368c43df363ebaa805f1d5656
icons/Icon-maskable-192.png,1698136351189,419e7818942c0c2a41b5744cd473f10a1d66278d2248c470dedac217d2f7cc0a
icons/Icon-maskable-512.png,1698136351189,a326e3b122e46588bbb8e9d8c283ea13ef01ac5368c43df363ebaa805f1d5656
5 changes: 3 additions & 2 deletions lib/classes/miniTB_prediction_class.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ class MiniTBPred {
final Map west;
final String date;
final Map wins;
final String proxy_country;

MiniTBPred(this.name, this.east, this.west, this.date, this.wins);
MiniTBPred(this.name, this.east, this.west, this.date, this.wins, this.proxy_country);
}

Map buildStandings(Map predictions) {
Expand Down Expand Up @@ -82,7 +83,7 @@ List<int> malus(MiniTBPred prediction, MiniTBPred reference) {
}

String miniTBStandings(List<MiniTBPred> preds, MiniTBPred yesterday) {
MiniTBPred reference = MiniTBPred("", {}, {}, "", {});
MiniTBPred reference = MiniTBPred("", {}, {}, "", {}, "");
for (var i = 0; i < preds.length; i++) {
if (preds[i].name == "Admin") {
reference = preds[i];
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/miniTB/miniTB_insert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class _InsertPredictionPageState extends State<InsertPredictionPage> {
builder: (context, snapshot) {
if (snapshot.hasData) {
List<MiniTBPred> preds = snapshot.data as List<MiniTBPred>;
MiniTBPred pred = MiniTBPred("", {}, {}, "", {});
MiniTBPred pred = MiniTBPred("", {}, {}, "", {}, "");
for (var i = 0; i < preds.length; i++) {
if (preds[i].name == miniTBParticipants[widget.index].name) {
pred = preds[i];
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/miniTB/minitb_nba_standings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MiniTBNBAStandings extends StatelessWidget {
builder: (context, snapshot) {
if (snapshot.hasData) {
List<MiniTBPred> preds = snapshot.data as List<MiniTBPred>;
MiniTBPred reference = MiniTBPred("", {}, {}, "", {});
MiniTBPred reference = MiniTBPred("", {}, {}, "", {}, "");
for (var i = 0; i < preds.length; i++) {
if (preds[i].name == "Admin") {
reference = preds[i];
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/miniTB/minitb_predictions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MiniTBPredictions extends StatelessWidget {
builder: (context, snapshot) {
if (snapshot.hasData) {
List<MiniTBPred> preds = snapshot.data as List<MiniTBPred>;
MiniTBPred reference = MiniTBPred("", {}, {}, "", {});
MiniTBPred reference = MiniTBPred("", {}, {}, "", {}, "");
for (var i = 0; i < preds.length; i++) {
if (preds[i].name == "Admin") {
reference = preds[i];
Expand Down Expand Up @@ -67,7 +67,7 @@ class MiniTBPredictions extends StatelessWidget {
shrinkWrap: true,
itemCount: miniTBParticipants.length - 1,
itemBuilder: (context, index) {
MiniTBPred pred = MiniTBPred("", {}, {}, "", {});
MiniTBPred pred = MiniTBPred("", {}, {}, "", {}, "");
for (var i = 0; i < preds.length; i++) {
if (preds[i].name ==
miniTBParticipants[index].name) {
Expand Down
7 changes: 4 additions & 3 deletions lib/pages/miniTB/minitb_standings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MiniTBStandings extends StatelessWidget {
builder: (context, snapshot) {
if (snapshot.hasData) {
List<MiniTBPred> preds = snapshot.data as List<MiniTBPred>;
MiniTBPred reference = MiniTBPred("", {}, {}, "", {});
MiniTBPred reference = MiniTBPred("", {}, {}, "", {}, "");
for (var i = 0; i < preds.length; i++) {
if (preds[i].name == "Admin") {
reference = preds[i];
Expand All @@ -31,6 +31,7 @@ class MiniTBStandings extends StatelessWidget {
String sponsor = sponsors[actualToday.weekday - 1];
bool isUpdated = (actualToday.day == todayDate.day) &&
(actualToday.month == todayDate.month);
String proxyCountry = reference.proxy_country;
return FutureBuilder(
future: DatabaseServiceMiniTB()
.dailyStandings(formatter.format(yesterdayDate)),
Expand Down Expand Up @@ -73,7 +74,7 @@ class MiniTBStandings extends StatelessWidget {
Padding(
padding: const EdgeInsets.fromLTRB(0, 20, 20, 10),
child: Text(
"Presented by $sponsor",
"Presented by $sponsor\nCourtesy of proxy in $proxyCountry",
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.grey[700],
Expand Down Expand Up @@ -129,7 +130,7 @@ class MiniTBStandings extends StatelessWidget {
onTap: () async => await launch(
WhatsAppUnilink(
text:
"*MiniTB Standings of the Day*\n_Presented by ${sponsor}_\n\n" +
"*MiniTB Standings of the Day*\n_Presented by ${sponsor}_\n_Courtesy of proxy in ${proxyCountry}_\n\n" +
miniTBStandings(preds, yesterday),
).toString(),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/services/database_miniTB.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class DatabaseServiceMiniTB {
westPred[westTeams[team]] = (doc.data() as Map)[westTeams[team]] ?? -1;
}

return MiniTBPred((doc.data() as Map)['name'] ?? '', eastPred, westPred, (doc.data() as Map)['date'] ?? '', {});
return MiniTBPred((doc.data() as Map)['name'] ?? '', eastPred, westPred, (doc.data() as Map)['date'] ?? '', {}, (doc.data() as Map)['proxy_country'] ?? '');
}).toList();
}

Expand All @@ -109,7 +109,7 @@ class DatabaseServiceMiniTB {
westPred[westTeams[team]] = (snapshot.data() as Map)[westTeams[team]] ?? -1;
wins[westTeams[team]] = (snapshot.data() as Map)['${westTeams[team]}-wins'] ?? "";
}
return MiniTBPred('', eastPred, westPred, '', wins);
return MiniTBPred('', eastPred, westPred, '', wins, (snapshot.data() as Map)['proxy_country'] ?? '');
}

// get passwords
Expand Down
18 changes: 14 additions & 4 deletions scripts/daily_minitb.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,21 @@ def get_daily_standings_from_api_2():
d = leaguestandings.LeagueStandings(proxy=proxy).get_dict()
except:
continue
proxy_ip = proxy.split(':')[0]
try:
ip_lookup_response = requests.get('https://geolocation-db.com/jsonp/' + proxy_ip)
ip_lookup_response = ip_lookup_response.content.decode().split("(")[1].strip(")")
ip_lookup_response = json.loads(ip_lookup_response)
proxy_country = ip_lookup_response['country_name']
except:
proxy_country = ""
print('Proxy country: ', proxy_country)
r = d['resultSets'][0]['rowSet']
standings = {}
for team in r:
standings[tricode_map[team[4]]] = {'integerValue': f'{team[7]}'}
standings[f'{tricode_map[team[4]]}-wins'] = {'stringValue': f'{team[16]}'}
return standings
return standings, proxy_country


def get_daily_standings_from_api():
Expand Down Expand Up @@ -95,7 +104,7 @@ def get_di_token():
return (r.json())['idToken']


def push_standings_to_db(standings):
def push_standings_to_db(standings, proxy_country):
document = {'fields': standings}
id_token = get_di_token()
headers = {'Authorization': f'Bearer {id_token}'}
Expand All @@ -110,6 +119,7 @@ def push_standings_to_db(standings):
url = f'https://firestore.googleapis.com/v1/projects/minitb-rs/databases/(default)/documents/predictions/Admin'
document['fields']['name'] = {'stringValue': 'Admin'}
document['fields']['date'] = {'stringValue': today_string}
document['fields']['proxy_country'] = {'stringValue': proxy_country}
resp = requests.patch(url, data=json.dumps(document), headers=headers)
if resp.status_code != 200:
print(resp.json())
Expand All @@ -118,8 +128,8 @@ def push_standings_to_db(standings):


def daily_minitb():
standings = get_daily_standings_from_api_2()
push_standings_to_db(standings)
standings, proxy_country = get_daily_standings_from_api_2()
push_standings_to_db(standings, proxy_country)


if __name__ == '__main__':
Expand Down

0 comments on commit 6a3ca32

Please sign in to comment.