{"id":2345,"date":"2024-01-19T22:24:00","date_gmt":"2024-01-19T22:24:00","guid":{"rendered":"https:\/\/www.jameshatton.co.uk\/blog\/?p=2345"},"modified":"2024-02-24T08:34:53","modified_gmt":"2024-02-24T08:34:53","slug":"random-games-to-plat-from-rawg","status":"publish","type":"post","link":"https:\/\/www.jameshatton.co.uk\/blog\/2024\/01\/19\/random-games-to-plat-from-rawg\/","title":{"rendered":"Random Game from RAWG"},"content":{"rendered":"\n<p>I enjoy video games so naturally have a backlog to get through. I like to randomly pick a game and if it suits my mood, I&#8217;ll play it or get another random game. Unfortunately rawg.io doesn&#8217;t have this feature so I&#8217;ve made one.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>I&#8217;ve done two options here and both depend on exporting my games list, as a CSV, from Rawg (within settings on rawg.io). Rawg does have an API and I may utilise this in future.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Option 1: Excel<\/h2>\n\n\n\n<p>I import the spreadsheet into the Owned tab of my Video Games spreadsheet and then if I refresh the sheet (by double-clicking into an unlocked cell), I get a new random title (D1:F1). The neat thing with this solution is I can filter the status so, for example, just show a random title from games &#8216;Not played&#8217;. <\/p>\n\n\n\n<p>The formula to achieve this is: <strong>=INDEX(A4:A10000,RANDBETWEEN(1,COUNTA(A4:A10000)),1)<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"840\" height=\"510\" data-attachment-id=\"2379\" data-permalink=\"https:\/\/www.jameshatton.co.uk\/blog\/2024\/01\/19\/random-games-to-plat-from-rawg\/xboxgamessheet-1\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.jameshatton.co.uk\/blog\/wp-content\/uploads\/2024\/02\/xboxgamessheet-1.png?fit=1249%2C759&amp;ssl=1\" data-orig-size=\"1249,759\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"xboxgamessheet-1\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.jameshatton.co.uk\/blog\/wp-content\/uploads\/2024\/02\/xboxgamessheet-1.png?fit=840%2C510&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.jameshatton.co.uk\/blog\/wp-content\/uploads\/2024\/02\/xboxgamessheet-1.png?resize=840%2C510&#038;ssl=1\" alt=\"\" class=\"wp-image-2379\" srcset=\"https:\/\/i0.wp.com\/www.jameshatton.co.uk\/blog\/wp-content\/uploads\/2024\/02\/xboxgamessheet-1.png?resize=1024%2C622&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.jameshatton.co.uk\/blog\/wp-content\/uploads\/2024\/02\/xboxgamessheet-1.png?resize=300%2C182&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.jameshatton.co.uk\/blog\/wp-content\/uploads\/2024\/02\/xboxgamessheet-1.png?resize=768%2C467&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.jameshatton.co.uk\/blog\/wp-content\/uploads\/2024\/02\/xboxgamessheet-1.png?w=1249&amp;ssl=1 1249w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Option 2: Python Program<\/h2>\n\n\n\n<p>The other option (just like I like playing with Python) is the following little program, which again needs the CSV export from Rawg. Here&#8217;s the program in operation, with the code beneath it. <\/p>\n\n\n\n<iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/python\/66441b7713?outputOnly=true&#038;runOption=run&#038;start=result\" width=\"100%\" height=\"600\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen><\/iframe>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\n#!\/bin\/python3\nimport random\nprint(&quot;RetroJimmyX&#039;s Random Game Picker to pick a title from my collection.\\n&quot;)\n\ngames_array = &#x5B;]\nmap_status = {&quot;Currently playing&quot;:0,&quot;Completed&quot;:1,&quot;Played&quot;:2,&quot;Not played&quot;:3,&quot;Total&quot;:4}\ngames_stats = &#x5B;0,0,0,0,0]\n\ndef loadgames():\n  global games_array, map_status, games_stats\n  gamesfile = open(&quot;games.csv&quot;,&quot;r&quot;)\n  for line in gamesfile:\n    games_array.append(line.replace(&quot;\\&quot;&quot;,&quot;&quot;).split(&quot;,&quot;))\n  gamesfile.close()\n  for game in games_array:\n    if game&#x5B;1] in map_status:\n      games_stats&#x5B;map_status&#x5B;game&#x5B;1]]] += 1\n  games_stats&#x5B;4] = len(games_array)\n  print(&quot;=====\\nSTATS\\n=====&quot;)\n  for i in range(len(map_status)):\n    print(str(list(map_status)&#x5B;i])+&quot;: &quot;+str(games_stats&#x5B;i]))\n\ndef menu_text():\n  print(&#039;&#039;&#039;\\n====\\nMENU\\n====\\nPlease make a choice below (or blank for 3):\\n1 for titles that are &#039;Not played&#039;\\n2 for titles that I am &#039;Currently playing&#039;\n3 for titles that I have not &#039;Completed&#039;\\nx to exit program\\n&#039;&#039;&#039;)\n\ndef get_title(options):\n  global games_array, map_status, games_stats\n  if options == &quot;1&quot;: game_selection = &#x5B;game for game in games_array if game&#x5B;1]==&quot;Not played&quot;]\n  elif options == &quot;2&quot;: game_selection = &#x5B;game for game in games_array if game&#x5B;1]==&quot;Currently playing&quot;]\n  else: game_selection = &#x5B;game for game in games_array if game&#x5B;1]!=&quot;Completed&quot;]\n  generate = &quot;&quot;\n  while generate != &quot;m&quot;:\n    num = random.randint(1,len(game_selection))\n    length = max(len(game_selection&#x5B;num]&#x5B;0]),len(game_selection&#x5B;num]&#x5B;2]))\n    print(&quot;\\n&quot;+&quot;*&quot;*length+&quot;\\n&quot;+game_selection&#x5B;num]&#x5B;0]+&quot; (&quot;+game_selection&#x5B;num]&#x5B;1]+&quot;)\\n&quot;+game_selection&#x5B;num]&#x5B;2]+&quot;*&quot;*length)\n    generate = input(&quot;Press ENTER for another game or type m to return to menu:&quot;)\n  return\n\ndef menu():\n  choice = &quot;a&quot;\n  while choice not in &quot;123&quot; or input != &quot;&quot;:\n    menu_text()\n    choice = input(&quot;Enter Choice: &quot;)\n    if choice not in &#x5B;&quot;1&quot;,&quot;2&quot;,&quot;3&quot;,&quot;x&quot;,&quot;&quot;]:\n      print(&quot;Please make sure to choose 1-3 or x to exit.&quot;)\n    elif choice == &quot;x&quot;:\n      print(&quot;Goodbye.&quot;)\n      exit()\n    else:\n      get_title(choice)\n\nloadgames()\nmenu()\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>I enjoy video games so naturally have a backlog to get through. I like to randomly pick a game and if it suits my mood, I&#8217;ll play it or get another random game. Unfortunately rawg.io doesn&#8217;t have this feature so I&#8217;ve made one.<\/p>\n","protected":false},"author":1,"featured_media":2383,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[92],"tags":[27,78],"class_list":["post-2345","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-gaming","tag-gaming","tag-programming"],"featured_image_src":"https:\/\/i0.wp.com\/www.jameshatton.co.uk\/blog\/wp-content\/uploads\/2024\/01\/rawg-random.png?fit=360%2C240&ssl=1","author_info":{"display_name":"james","author_link":"https:\/\/www.jameshatton.co.uk\/blog\/author\/james\/"},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.jameshatton.co.uk\/blog\/wp-content\/uploads\/2024\/01\/rawg-random.png?fit=360%2C240&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p89zH1-BP","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jameshatton.co.uk\/blog\/wp-json\/wp\/v2\/posts\/2345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jameshatton.co.uk\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jameshatton.co.uk\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jameshatton.co.uk\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jameshatton.co.uk\/blog\/wp-json\/wp\/v2\/comments?post=2345"}],"version-history":[{"count":3,"href":"https:\/\/www.jameshatton.co.uk\/blog\/wp-json\/wp\/v2\/posts\/2345\/revisions"}],"predecessor-version":[{"id":2382,"href":"https:\/\/www.jameshatton.co.uk\/blog\/wp-json\/wp\/v2\/posts\/2345\/revisions\/2382"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jameshatton.co.uk\/blog\/wp-json\/wp\/v2\/media\/2383"}],"wp:attachment":[{"href":"https:\/\/www.jameshatton.co.uk\/blog\/wp-json\/wp\/v2\/media?parent=2345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jameshatton.co.uk\/blog\/wp-json\/wp\/v2\/categories?post=2345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jameshatton.co.uk\/blog\/wp-json\/wp\/v2\/tags?post=2345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}