• Activity
  • Votes
  • Comments
  • New
  • All activity
  • Showing unfiltered topic list. Back to normal view
    1. Python Loops for JSON

      How the heck do these work? I've cobbled together the script below for my bot (using Limnoria) to return the F1 standings in a line. Right now it returns the first value perfectly, but I can't...

      How the heck do these work? I've cobbled together the script below for my bot (using Limnoria) to return the F1 standings in a line. Right now it returns the first value perfectly, but I can't figure out the loop to get the other drivers at all.

      The script
      import supybot.utils as utils
      from supybot.commands import *
      import supybot.plugins as plugins
      import supybot.ircutils as ircutils
      import supybot.callbacks as callbacks
      import supybot.ircmsgs as ircmsgs
      import requests
      import os
      import collections
      import json
      
      try:
          from supybot.i18n import PluginInternationalization
      
          _ = PluginInternationalization("F1")
      except ImportError:
          _ = lambda x: x
      
      
      class F1(callbacks.Plugin):
          """Uses API to retrieve information"""
      
          threaded = True
      
          def f1(self, irc, msg, args):
              """
              F1 Standings
              """
      
              channel = msg.args[0]
              data = requests.get("https://ergast.com/api/f1/2022/driverStandings.json")
              data = json.loads(data.content)["MRData"]["StandingsTable"]["StandingsLists"][0]["DriverStandings"][0]
      
              name = data["Driver"]["code"]
              position = data["positionText"].zfill(2)
              points = data["points"]
      
              output = ", ".join(['\x0306\x02' + name + '\x0303' + " [" + position + ", "+ points + "]"])
              irc.reply(output)
      
          result = wrap(f1)
      
      Class = F1
      

      The output should be

      VER [1, 125], LEC [2, 116], PER [3, 110], RUS [4, 84], SAI [5, 83], HAM [6, 50], NOR [7, 48], BOT [8, 40], OCO [9, 30], MAG [10, 15], RIC [11, 11], TSU [12, 11], ALO [13, 10], GAS [14, 6], VET [15, 5], ALB [16, 3], STR [17, 2], ZHO [18, 1], MSC [19, 0], HUL [20, 0], LAT [21, 0]
      

      ...but it only returns VER [1, 125]

      I'm in that state where I can read the stuff, but when I put it together, it doesn't always work.

      Final script
      # this accepts @champ or @constructor with an optional year
      # and also @gp with an optional race number for the current season
      
      
      import supybot.utils as utils
      from supybot.commands import *
      import supybot.plugins as plugins
      import supybot.ircutils as ircutils
      import supybot.callbacks as callbacks
      import supybot.ircmsgs as ircmsgs
      import requests
      import os
      import collections
      import json
      
      try:
          from supybot.i18n import PluginInternationalization
      
          _ = PluginInternationalization("F1")
      except ImportError:
          _ = lambda x: x
      
      
      class F1(callbacks.Plugin):
          """Uses API to retrieve information"""
      
          threaded = True
      
          def champ(self, irc, msg, args, year):
              """<year>
              Call standings by year
              F1 Standings
              """
      
              data = requests.get("https://ergast.com/api/f1/current/driverStandings.json")
              if year:
                  data = requests.get(
                      "https://ergast.com/api/f1/%s/driverStandings.json" % (year)
                  )
              driver_standings = json.loads(data.content)["MRData"]["StandingsTable"][
                  "StandingsLists"
              ][0]["DriverStandings"]
              string_segments = []
      
              for driver in driver_standings:
                  name = driver["Driver"]["code"]
                  position = driver["positionText"]
                  points = driver["points"]
                  string_segments.append(f"\x035{name}\x0F {points}")
      
              irc.reply(", ".join(string_segments))
      
          champ = wrap(champ, [optional("int")])
      
          def gp(self, irc, msg, args, race):
              """<year>
              Call standings by year
              F1 Standings
              """
      
              data = requests.get("https://ergast.com/api/f1/current/last/results.json")
              if race:
                  data = requests.get(
                      "https://ergast.com/api/f1/current/%s/results.json" % (race)
                  )
              driver_result = json.loads(data.content)["MRData"]["RaceTable"]["Races"][0][
                  "Results"
              ]
              string_segments = []
      
              for driver in driver_result:
                  name = driver["Driver"]["code"]
                  position = driver["positionText"]
                  points = driver["points"]
                  string_segments.append(f"{position} \x035{name}\x0F {points}")
      
              irc.reply(", ".join(string_segments))
      
          gp = wrap(gp, [optional("int")])
      
          def constructor(self, irc, msg, args, year):
              """<year>
              Call standings by year
              F1 Standings
              """
      
              data = requests.get(
                  "https://ergast.com/api/f1/current/constructorStandings.json"
              )
              if year:
                  data = requests.get(
                      "https://ergast.com/api/f1/current/constructorStandings.json" % (year)
                  )
              driver_result = json.loads(data.content)["MRData"]["StandingsTable"][
                  "StandingsLists"
              ][0]["ConstructorStandings"]
              string_segments = []
      
              for driver in driver_result:
                  name = driver["Constructor"]["name"]
                  position = driver["positionText"]
                  points = driver["points"]
                  string_segments.append(f"{position} \x035{name}\x0F {points}")
      
              irc.reply(", ".join(string_segments))
      
          constructor = wrap(constructor, [optional("int")])
      
      
      Class = F1
      
      3 votes
    2. AlbumLove recommendations thread: June 2022

      Choose one album that you love that you think deserves more love Tell us what it is, and why. Previous posts in series Additional Details What is this? It's a new post series I'm trying out! Each...

      Choose one album
      that you love
      that you think deserves more love

      Tell us what it is, and why.


      Previous posts in series


      Additional Details

      What is this?

      It's a new post series I'm trying out! Each month people can use the AlbumLove thread to post an album they love and explore those posted by others.

      I'm planning to put up a new AlbumLove thread on the first of each month for a few months to see how these go as a trial run. If people like it we can keep it going — if they don’t it’ll fizzle out and I’ll stop.

      Why AlbumLove?

      In this day and age, algorithmic recommendations for music are easy to come by, and it's trivial to seek out new music that interests you by searching online. AlbumLove offers an opportunity to sift through music loved by others, including those who might have divergent tastes from you. Think of this as an opportunity to listen outside of your comfort zone, with music that you know someone else adores, from a small pool of thoughtful hand-selected options.

      What do I post?

      Any album that you love and that you feel deserves more appreciation. There are no restrictions on genre, year, or anything else, and nothing is “too popular” or “too niche”. If you think it needs more love — for whatever reason — then it’s welcome in AlbumLove.

      Name the artist and the album, and then, most importantly, share what you love about the album. It could be the music itself, but it could also be your associations with it -- maybe the album reminds you of someone you love, or you saw the band live and got a new appreciation for the studio songs.

      Also, commenting on others' recommendations is encouraged! If you love something that someone else shared, let them know!

      Do I have to listen to what everyone else posts?

      Nope. You don't have to listen to anything if you don't want to. This is about creating a menu of options that people can explore as they wish.

      Can I post more than one album in a month?

      Nope. Limit one! This helps us be more selective about what we choose, as well as preventing the threads from getting flooded with too many contributions to keep track of.

      Why albums and not songs/artists?

      I like albums. :)

      Seriously though, I feel like it's a very different thing to like an album as a whole versus a few songs or just an artist's general vibe. I like the idea of quantizing music for appreciation in the same way we might do with books or movies.

      What about EPs?

      Fair game!

      5 votes
    3. Do you think an ~engineering group would make sense?

      I think it would, that's something that interests a vast number of users. Things like construction, bridges, buildings, city planning, trains, etc. Right now they can go to ~misc or ~design which...

      I think it would, that's something that interests a vast number of users. Things like construction, bridges, buildings, city planning, trains, etc. Right now they can go to ~misc or ~design which doesn't seem appropriate.

      5 votes
    4. Acapellas

      Does anyone know of any good acapellas or tracks with good vox? I don't really have a specific tone/feel in mind. Anything, really!

      5 votes
    5. Introducing Zed — A lightning-fast, collaborative code editor written in Rust

      From Hacker News: Founder of Atom here. We're building the spiritual successor to Atom over at https://zed.dev. We learned a lot with Atom and had a great time, but it always fell short of our...

      From Hacker News:

      Founder of Atom here. We're building the spiritual successor to Atom over at https://zed.dev.

      We learned a lot with Atom and had a great time, but it always fell short of our vision. With Zed we're going to get it right. Written in Rust, custom native UI framework, engineered to be collaborative. Just starting our private alpha this week, so the timing of this announcement feels quite fitting.

      14 votes
    6. TV Tuesdays Free Talk

      Have you watched any TV shows recently you want to discuss? Any shows you want to recommend or are hyped about? Feel free to discuss anything here. Please just try to provide fair warning of...

      Have you watched any TV shows recently you want to discuss? Any shows you want to recommend or are hyped about? Feel free to discuss anything here.

      Please just try to provide fair warning of spoilers if you can.

      2 votes
    7. What have you been listening to this week?

      What have you been listening to this week? You don't need to do a 6000 word review if you don't want to, but please write something! If you've just picked up some music, please update on that as...

      What have you been listening to this week? You don't need to do a 6000 word review if you don't want to, but please write something! If you've just picked up some music, please update on that as well, we'd love to see your hauls :)

      Feel free to give recs or discuss anything about each others' listening habits.

      You can make a chart if you use last.fm:

      http://www.tapmusic.net/lastfm/

      Remember that linking directly to your image will update with your future listening, make sure to reupload to somewhere like imgur if you'd like it to remain what you have at the time of posting.

      2 votes
    8. My experience with Windows 10

      I'm a longtime Linux user, and I haven't used Windows in a while aside from just launching games from Steam on my living room computer, but my new work laptop is Microsoft's flagship Surface Pro 4...

      I'm a longtime Linux user, and I haven't used Windows in a while aside from just launching games from Steam on my living room computer, but my new work laptop is Microsoft's flagship Surface Pro 4 so I figured it'd be the best experience you can have on a Windows machine.

      I got the laptop in yesterday, and here's the summary of my experience:

      • I am required by IT to use Chrome. To install Chrome, I had to click through no fewer than three "Are you sure you don't want to use Microsoft's more secure, faster browser?" banners to do so.

      • When I plug in my external monitor, by default, the two monitors were mirrored; when I went into display settings, it didn't show the external monitor until I closed and reopened the settings menu.

      • I have an Apple Magic Touchpad 2, and I had some issues getting it set up on Ubuntu 20.04 when I initially got it. These problems are now solved on the latest version of Ubuntu, but I was expecting a nice contrast in a good plug-and-play experience on Windows. Instead, I had to install sketchy drivers from some random GitHub page to get it to work properly.

      • I've had some minor annoyances with my audio interface (a Zoom R-22) not being set as the default when I want it to be on Ubuntu, and I was really looking forward to getting a smooth video calling experience with my nice mic and interface on Windows. Lo and behold, the R-22 audio input - the whole reason I have it - doesn't work at all, at least in the Zoom video calling app.

      • On Ubuntu, I use QV4L2 to configure the framing, zoom, exposure, etc of my camera. It's a bit clunky, and I was looking forward to having a smooth experience with this on the premier business OS. Unfortunately, the camera on this laptop has extremely aggressive aperture priority mode enabled, and there is no first-party app to configure it! The documentation tells me to go to Settings -> Devices -> Camera but there is no such menu item. So, I just look either washed-out or ultra-dark in every video call.

      • After running Windows Update and rebooting, I was greeted with a full-screen and quite annoying to exit tutorial for Microsoft Teams - an app I did not install, because my company uses Slack.

      This in addition to some setup papercuts, but I think those were probably due to my corporate IT's process rather than Windows itself.

      Is this common? Do people who use Windows just... put up with this kind of thing? Or am I having an exceptionally bad experience for some reason?

      15 votes
    9. What programming/technical projects have you been working on?

      This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's...

      This is a recurring post to discuss programming or other technical projects that we've been working on. Tell us about one of your recent projects, either at work or personal projects. What's interesting about it? Are you having trouble with anything?

      6 votes
    10. What have you been listening to this week?

      What have you been listening to this week? You don't need to do a 6000 word review if you don't want to, but please write something! If you've just picked up some music, please update on that as...

      What have you been listening to this week? You don't need to do a 6000 word review if you don't want to, but please write something! If you've just picked up some music, please update on that as well, we'd love to see your hauls :)

      Feel free to give recs or discuss anything about each others' listening habits.

      You can make a chart if you use last.fm:

      http://www.tapmusic.net/lastfm/

      Remember that linking directly to your image will update with your future listening, make sure to reupload to somewhere like imgur if you'd like it to remain what you have at the time of posting.

      6 votes
    11. Fitness Weekly Discussion

      What have you been doing lately for your own fitness? Try out any new programs or exercises? Have any questions for others about your training? Want to vent about poor behavior in the gym? Started...

      What have you been doing lately for your own fitness? Try out any new programs or exercises? Have any questions for others about your training? Want to vent about poor behavior in the gym? Started a new diet or have a new recipe you want to share? Anything else health and wellness related?

      8 votes
    12. Weekly megathread for news/updates/discussion of Russian invasion of Ukraine - June 3

      This thread is posted Monday/Wednesday/Friday - please try to post relevant content in here, such as news, updates, opinion articles, etc. Especially significant updates may warrant a separate...

      This thread is posted Monday/Wednesday/Friday - please try to post relevant content in here, such as news, updates, opinion articles, etc. Especially significant updates may warrant a separate topic, but most should be posted here.

      If you'd like to help support Ukraine, please visit the official site at https://help.gov.ua/ - an official portal for those who want to provide humanitarian or financial assistance to people of Ukraine, businesses or the government at the times of resistance against the Russian aggression.

      15 votes