Tradingeconomics wants you to pay a ridiculous amount for the privilege of exporting public data as csv.

Their site obtains economic data from some api in base64, gzip and XOR encrypted form. I (kinda, got help from Chatgpt) made a script to decrypt and convert data to a readable excel sheet.

https://pastebin.com/raw/gxXZnN37

  • GaveUp [she/her]
    ·
    edit-2
    1 month ago

    This is sus as fuck loool. What data is this? That site has a bunch of different sets. This is grabbing data from some unidentifiable CloudFront URI at first glance. I don't think any stranger should click on that to check nor should they put the contents of that site into an excel file and then open it lol

    But to be completely honest, I do think 99% it's completely fine and does exactly what you said. Nice job and thanks for sharing anyways haha <3

    • FuckyWucky [none/use name]
      hexagon
      ·
      edit-2
      1 month ago

      They use cloudfront for serving data used in graph. No need to use the link provided in the script (that one is for USD Korean Won exchange rate). You'll have to go to a data url

      https://tradingeconomics.com/laos/consumer-price-index-cpi

      Press F12 to bring up debug tools, click on network and change time series on the graph to make the URL containing graph data show up on network tab. Then paste it in the script and it'll make the sheet.

      • GaveUp [she/her]
        ·
        1 month ago

        Thanks for sharing the source. My issue with the cloudfront uri was that by just looking at it, you can't actually tell that tradingeconomics owns it. For all we know it could've been spun up by anybody

  • ZWQbpkzl [none/use name]
    ·
    1 month ago

    Few notes:

    • there's an isoformat method you can use instead of manually specifying the iso format for dates.
    • lol at that api-key key.
    • replace if good; return happy; else; return sad with if bad; return sad; return happy. Its easier to read and saves you some indents. It might offend functional programmers but this is python.
    • pandas is a huge dep and all your using it for is to make an xlsx. If you used CSV it all be standard python and the script would be more portable.

    Critiquing because its otherwise really good. Slap some argparsing on top. If you want to do bulk downloads look into asyncio and httpx.

    • GaveUp [she/her]
      ·
      edit-2
      1 month ago

      replace if good; return happy; else; return sad with if bad; return sad; return happy. Its easier to read and saves you some indents

      I will forever hate whatever bazinga wrote this into whatever style guide that has this opinion. The first is way easier imo, it's explicit that if this happens, then return this, if anything else, return that. The latter you have to fill in a tiny gap when reading to put in the inferred else clause that's not written down to figure it out

      Regardless, if I wanted to be an asshole for work politics in this situation I'd comment "aKScHuaLLy return happy if good else sad is better"