I am completely new to all of this so please forgive any issues with how I'm describing and name things. I have an HTML page where the user enters a portion of a URL string in order to launch a new window with the complete URL string. I'd rather just lookup the portion of the URL using an API to create a JSON file and find it automatically. Any ideas how I can accomplish this without user intervention?
HTML (contains text box and button to launch a new window, which I would like to bypass this altogether)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Cast Challonge</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#button').click(function(e) {
var inputvalue = $("#input").val();
window.open(("http://challonge.com/"+inputvalue+"/module?theme=5928&selected-round-
filter=2&show_final_results=0&multiplier=2&show_tournament_name=1&scale_to_fit=1"),"Tournament
Display","width=1280,height=720,resizable=no, toolbar=no, scrollbars=no, menubar=no, status=no,
directories=no");
});
});
</script>
</head>
<body>
<input type="text" value="" id="input">
<button type="button" id="button">Submit Tournament ID</button>
</body>
</html>
My sample API call is as follows:
[
{
"tournament": {
"id": 9838153,
"name": "2021/05/22 Saturday Night 8-Ball",
"url": "BnkSat0522",
"description": "",
"tournament_type": "double elimination",
"started_at": "2021-05-23T07:01:41.429+07:00",
"completed_at": "2021-05-23T12:54:30.331+07:00",
"require_score_agreement": false,
"notify_users_when_matches_open": true,
"created_at": "2021-05-23T03:41:49.015+07:00",
"updated_at": "2021-05-23T12:54:30.580+07:00",
"state": "complete",
"open_signup": false,
"notify_users_when_the_tournament_ends": true,
"progress_meter": 100,
"quick_advance": false,
"hold_third_place_match": false,
"pts_for_game_win": "0.0",
"pts_for_game_tie": "0.0",
"pts_for_match_win": "1.0",
"pts_for_match_tie": "0.5",
"pts_for_bye": "1.0",
"swiss_rounds": 0,
"private": false,
"ranked_by": "match wins",
"show_rounds": true,
"hide_forum": false,
"sequential_pairings": false,
"accept_attachments": false,
"rr_pts_for_game_win": "0.0",
"rr_pts_for_game_tie": "0.0",
"rr_pts_for_match_win": "1.0",
"rr_pts_for_match_tie": "0.5",
"created_by_api": false,
"credit_capped": false,
"category": null,
"hide_seeds": false,
"prediction_method": 0,
"predictions_opened_at": null,
"anonymous_voting": false,
"max_predictions_per_user": 1,
"signup_cap": null,
"game_id": 773,
"participants_count": 24,
"group_stages_enabled": false,
"allow_participant_match_reporting": false,
"teams": false,
"check_in_duration": null,
"start_at": null,
"started_checking_in_at": null,
"tie_breaks": [
"match wins vs tied",
"game wins",
"points scored"
],
"locked_at": null,
"event_id": null,
"public_predictions_before_start_time": false,
"ranked": false,
"grand_finals_modifier": null,
"predict_the_losers_bracket": false,
"spam": null,
"ham": null,
"rr_iterations": 1,
"tournament_registration_id": null,
"donation_contest_enabled": null,
"mandatory_donation": null,
"non_elimination_tournament_data": {
"participants_per_match": ""
},
"auto_assign_stations": null,
"only_start_matches_with_stations": null,
"registration_fee": "0.0",
"registration_type": "free",
"split_participants": false,
"allowed_regions": [
],
"show_participant_country": null,
"program_id": null,
"program_classification_ids_allowed": null,
"team_size_range": null,
"toxic": null,
"description_source": "",
"subdomain": null,
"full_challonge_url": "https://challonge.com/BnkSat0522",
"live_image_url": "https://challonge.com/BnkSat0522.svg",
"sign_up_url": null,
"review_before_finalizing": true,
"accepting_predictions": false,
"participants_locked": true,
"game_name": "8-ball",
"participants_swappable": false,
"team_convertable": false,
"group_stages_were_started": false
}
},
{
"tournament": {
"id": 9845539,
"name": "2021/05/24 Monday Night 10-Ball",
"url": "20210524",
"description": "",
"tournament_type": "double elimination",
"started_at": "2021-05-25T06:34:46.053+07:00",
"completed_at": "2021-05-25T10:54:03.406+07:00",
"require_score_agreement": false,
"notify_users_when_matches_open": true,
"created_at": "2021-05-25T04:01:56.922+07:00",
"updated_at": "2021-05-25T10:54:03.589+07:00",
"state": "complete",
"open_signup": false,
"notify_users_when_the_tournament_ends": true,
"progress_meter": 100,
"quick_advance": false,
"hold_third_place_match": false,
"pts_for_game_win": "0.0",
"pts_for_game_tie": "0.0",
"pts_for_match_win": "1.0",
"pts_for_match_tie": "0.5",
"pts_for_bye": "1.0",
"swiss_rounds": 0,
"private": false,
"ranked_by": "match wins",
"show_rounds": true,
"hide_forum": false,
"sequential_pairings": false,
"accept_attachments": false,
"rr_pts_for_game_win": "0.0",
"rr_pts_for_game_tie": "0.0",
"rr_pts_for_match_win": "1.0",
"rr_pts_for_match_tie": "0.5",
"created_by_api": false,
"credit_capped": false,
"category": null,
"hide_seeds": false,
"prediction_method": 0,
"predictions_opened_at": null,
"anonymous_voting": false,
"max_predictions_per_user": 1,
"signup_cap": null,
"game_id": 6341,
"participants_count": 22,
"group_stages_enabled": false,
"allow_participant_match_reporting": true,
"teams": false,
"check_in_duration": null,
"start_at": null,
"started_checking_in_at": null,
"tie_breaks": [
"match wins vs tied",
"game wins",
"points scored"
],
"locked_at": null,
"event_id": null,
"public_predictions_before_start_time": false,
"ranked": false,
"grand_finals_modifier": null,
"predict_the_losers_bracket": false,
"spam": null,
"ham": null,
"rr_iterations": 1,
"tournament_registration_id": null,
"donation_contest_enabled": null,
"mandatory_donation": null,
"non_elimination_tournament_data": {
"participants_per_match": ""
},
"auto_assign_stations": false,
"only_start_matches_with_stations": false,
"registration_fee": "0.0",
"registration_type": "free",
"split_participants": false,
"allowed_regions": [
],
"show_participant_country": null,
"program_id": null,
"program_classification_ids_allowed": null,
"team_size_range": null,
"toxic": null,
"description_source": "",
"subdomain": null,
"full_challonge_url": "https://challonge.com/20210524",
"live_image_url": "https://challonge.com/20210524.svg",
"sign_up_url": null,
"review_before_finalizing": true,
"accepting_predictions": false,
"participants_locked": true,
"game_name": "10-Ball",
"participants_swappable": false,
"team_convertable": false,
"group_stages_were_started": false
}
},
{
"tournament": {
"id": 9851001,
"name": "2021/05/26 Wednesday Night 9-Ball",
"url": "20210526",
"description": "",
"tournament_type": "double elimination",
"started_at": "2021-05-26T20:48:53.085+07:00",
"completed_at": null,
"require_score_agreement": false,
"notify_users_when_matches_open": true,
"created_at": "2021-05-26T20:46:47.342+07:00",
"updated_at": "2021-05-26T20:48:53.158+07:00",
"state": "underway",
"open_signup": false,
"notify_users_when_the_tournament_ends": true,
"progress_meter": 0,
"quick_advance": false,
"hold_third_place_match": false,
"pts_for_game_win": "0.0",
"pts_for_game_tie": "0.0",
"pts_for_match_win": "1.0",
"pts_for_match_tie": "0.5",
"pts_for_bye": "1.0",
"swiss_rounds": 0,
"private": false,
"ranked_by": "match wins",
"show_rounds": true,
"hide_forum": true,
"sequential_pairings": false,
"accept_attachments": false,
"rr_pts_for_game_win": "0.0",
"rr_pts_for_game_tie": "0.0",
"rr_pts_for_match_win": "1.0",
"rr_pts_for_match_tie": "0.5",
"created_by_api": false,
"credit_capped": false,
"category": null,
"hide_seeds": false,
"prediction_method": 0,
"predictions_opened_at": null,
"anonymous_voting": false,
"max_predictions_per_user": 1,
"signup_cap": null,
"game_id": 485,
"participants_count": 2,
"group_stages_enabled": false,
"allow_participant_match_reporting": false,
"teams": false,
"check_in_duration": null,
"start_at": null,
"started_checking_in_at": null,
"tie_breaks": [
"match wins vs tied",
"game wins",
"points scored"
],
"locked_at": null,
"event_id": null,
"public_predictions_before_start_time": false,
"ranked": false,
"grand_finals_modifier": null,
"predict_the_losers_bracket": false,
"spam": null,
"ham": null,
"rr_iterations": 1,
"tournament_registration_id": null,
"donation_contest_enabled": null,
"mandatory_donation": null,
"non_elimination_tournament_data": {
"participants_per_match": ""
},
"auto_assign_stations": null,
"only_start_matches_with_stations": null,
"registration_fee": "0.0",
"registration_type": "free",
"split_participants": false,
"allowed_regions": [
],
"show_participant_country": null,
"program_id": null,
"program_classification_ids_allowed": null,
"team_size_range": null,
"toxic": null,
"description_source": "",
"subdomain": null,
"full_challonge_url": "https://challonge.com/20210526",
"live_image_url": "https://challonge.com/20210526.svg",
"sign_up_url": null,
"review_before_finalizing": true,
"accepting_predictions": false,
"participants_locked": true,
"game_name": "9-ball",
"participants_swappable": false,
"team_convertable": false,
"group_stages_were_started": false
}
}
]
Where I am trying to grab a tournament that the state is "underway" and return "url" that can then be used to launch a complete URL as described above.
I've created the following:
<?php
$apikey = 'MyAPIKEY';
$contents_api = fopen("https://api.challonge.com/v1/tournaments.json?
state=all&api_key=$apikey", "r");
$json = stream_get_contents($contents_api);
$jsonData = json_decode($json, TRUE);
print $jsonData[count($jsonData)-1]['tournament']['url'];
?>
Now I need to figure out how to grab this information and load the page!!!!
Again, I know this is probably not the best way to ask however, any guidance pointing me in the correct direction would be very helpful.
I was able to get what I wanted using:
<?php
$page = $_SERVER['PHP_SELF'];
$sec = "10";
$apikey = 'MYAPIKEY';
$contents_api = fopen("https://api.challonge.com/v1/tournaments.json?state=all&api_key=$apikey", "r");
$json = stream_get_contents($contents_api);
$jsonData = json_decode($json, TRUE);
//print $jsonData[count($jsonData)-1]['tournament']['url'];
$inputvalue = $jsonData[count($jsonData)-1]['tournament']['url'];
$url= "http://challonge.com/$inputvalue/module?selected-round-filter=2&show_final_results=0&multiplier=2&show_tournament_name=1&scale_to_fit=1"
?>
<html>
<head>
<script>
location.replace("<?php echo $url; ?>");
</script>
<meta http-equiv="refresh" content="<?php echo $sec ?>;URL='<?php echo $page?>'">
</head>
</html>
I'm developing a react application and in my state I have the data saved that I try to read. When I JSON.stringify the device data "console.log"'it out, look like this:
{
"ActTime": 1509988664,
"ServerTime": "2017-11-06 18:17:44",
"Sunrise": "07:25",
"Sunset": "15:53",
"result": [
{
"AddjMulti": 1,
"AddjMulti2": 1,
"AddjValue": 0,
"AddjValue2": 0,
"BatteryLevel": 255,
"CustomImage": 0,
"Data": "On",
"Description": "",
"Favorite": 1,
"HardwareID": 2,
"HardwareName": "Controller",
"HardwareType": "OpenZWave USB",
"HardwareTypeVal": 21,
"HaveDimmer": true,
"HaveGroupCmd": true,
"HaveTimeout": false,
"ID": "00000501",
"Image": "Light",
"IsSubDevice": false,
"LastUpdate": "2017-11-06 15:42:00",
"Level": 0,
"LevelInt": 0,
"MaxDimLevel": 100,
"Name": "Vardagsrum",
"Notifications": "false",
"PlanID": "0",
"PlanIDs": [
0
],
"Protected": false,
"ShowNotifications": true,
"SignalLevel": "-",
"Status": "On",
"StrParam1": "",
"StrParam2": "",
"SubType": "Switch",
"SwitchType": "On/Off",
"SwitchTypeVal": 0,
"Timers": "false",
"Type": "Light/Switch",
"TypeImg": "lightbulb",
"Unit": 1,
"Used": 1,
"UsedByCamera": false,
"XOffset": "0",
"YOffset": "0",
"idx": "3"
}
],
"status": "OK",
"title": "Devices"
}
If I want to read the status data I just do: device['status'] I get "OK", but what if I want to access the result data in the device?
I thought that device['result'][0]['Status'] would give my 'Ok, but I just get Uncaught TypeError: Cannot read property '0' of undefined ???
How do I read the result data in the device??
To do this device['result'][0]['Status'] you want to ensure your device data is not a string but a proper JSON object. You could JSON.parse() to convert it if it's not already an object.
Also ensure the data is available before trying that.
Try to use map method over result array.
Something like this:
result.map((item,index)=>{
console.log(item[index].AddjMulti);
})
How can I check recorded track is uploaded and active for embed.
I want to show embed preview of track once it upload is done.
but I am getting 404 error from scPlayer api while resolving the url.
Is possible to track availability of track, based on that i can use sCplayer()
for resolving track.
Any help?
Thanks
Peter
I know in the /tracks resource there is a attribute called state which could be what you're looking for.
On their docs, the example value they give is finished, so maybe it would read uploading or processing before the track is ready. NB: I haven't tried this myself.
{
"id": 13158665,
"created_at": "2011/04/06 15:37:43 +0000",
"user_id": 3699101,
"duration": 18109,
"commentable": true,
"state": "finished",
"sharing": "public",
"tag_list": "soundcloud:source=iphone-record",
"permalink": "munching-at-tiannas-house",
"description": null,
"streamable": true,
"downloadable": true,
"genre": null,
"release": null,
"purchase_url": null,
"label_id": null,
"label_name": null,
"isrc": null,
"video_url": null,
"track_type": "recording",
"key_signature": null,
"bpm": null,
"title": "Munching at Tiannas house",
"release_year": null,
"release_month": null,
"release_day": null,
"original_format": "m4a",
"original_content_size": 10211857,
"license": "all-rights-reserved",
"uri": "http://api.soundcloud.com/tracks/13158665",
"permalink_url": "http://soundcloud.com/user2835985/munching-at-tiannas-house",
"artwork_url": null,
"waveform_url": "http://w1.sndcdn.com/fxguEjG4ax6B_m.png",
"user": {
"id": 3699101,
"permalink": "user2835985",
"username": "user2835985",
"uri": "http://api.soundcloud.com/users/3699101",
"permalink_url": "http://soundcloud.com/user2835985",
"avatar_url": "http://a1.sndcdn.com/images/default_avatar_large.png?142a848"
},
"stream_url": "http://api.soundcloud.com/tracks/13158665/stream",
"download_url": "http://api.soundcloud.com/tracks/13158665/download",
"playback_count": 0,
"download_count": 0,
"favoritings_count": 0,
"comment_count": 0,
"created_with": {
"id": 124,
"name": "SoundCloud iPhone",
"uri": "http://api.soundcloud.com/apps/124",
"permalink_url": "http://soundcloud.com/apps/iphone"
},
"attachments_uri": "http://api.soundcloud.com/tracks/13158665/attachments"
}
from: http://developers.soundcloud.com/docs/api/tracks
alternatively, there could be another value, like duration or stream_url that will read NULL until the track is ready.