Python script and Shortcut to view the amount invested


#1

Hi all

Just made a small python script that lets you check the amount that has been invested in Monzo so far.

I’ve seen lots of people saying the site is behind, so if you run this it will quickly tell you how much has been invested.

To run, you’ll need to have Beautiful Soup and URLlib.

I also made a Shortcut that runs in the Shortcuts app: https://www.icloud.com/shortcuts/e6e5f128ede04660929792e1c70b7515

Hope you find it useful!

Thanks


#2

Just curious… the endpoint returns JSON for me… how does this BeautifulSoup thing even parse it?


#3

I’m pretty new to Python and it was the only way I knew how to scrape a site. I tried to use Requests but couldn’t figure it out.

Thanks! :slightly_smiling_face:


#4

Also I don’t really know what category this should be in, so apologies if it is in the wrong one!


(Tommy Long) #5

Or an alternative in JavaScript. Just press F12 in Chrome to open up Developer Tools, go to the Console and paste this in and then press Return!

(await (await fetch("https://api.monzo.com/crowdfunding-investment/total")).json()).invested_amount

Or the fatter (and friendly) version of the above:

let url = "https://api.monzo.com/crowdfunding-investment/total"

let response = await fetch(url)

let data = await response.json()

data.invested_amount

#6

I have no experience in JavaScript. Wanted to try using the API in Python as I haven’t every done something like it before. :slight_smile:


#7

Given that the endpoint provides JSON, something like this might be easier:

data = requests.get("https://api.monzo.com/crowdfunding-investment/total").json()

where data is a dictionary with the same keys/values as the JSON.


#8

I’ll try it out now - thanks!


#9

Wow, thats a lot neater! I’m going to implement it and update the script.


#10

Can’t seem to get it to work. Having issues splitting it for the investment variable.


Also just made a Shortcut! https://www.icloud.com/shortcuts/e6e5f128ede04660929792e1c70b7515


#11

Ultimately, you could tidy up some of the casting/string manipulation, but keeping it close to your original version:


#12

Thank you! Looks a lot cleaner. Thanks for your help :slightly_smiling_face:

Is it ok if I update the repo, or do you want to make a pull request?

Thanks!


#13

I’ve no problem with you updating your repo with it.


(Hugh Wells) #14

Neat! I was going to make something like this but hitting refresh was lower effort :sweat_smile:


#15

Glad you like it!

I made it as I hadn’t used Python in a while and wanted to try out using an API. Was a fun little project!


(Marcelo Gazzola Ribeiro) #16

Cool! I am trying to fetch information from my account using python and requests, but I am getting errors when attempt to authenticate. Have you tried it before? Could you help me please? Cheers!


#17

Hello, I haven’t used that part of the api so wouldn’t know. Sorry!


#18

I tried Tommy5dollar’s recipe and got this as an answer… 199999955400

I guess those are Venezuelan Bolivars or somesuch? :grinning:


#19

Divide it by 10,000 and you get £19,999,995.54, just a tad below the £20m because +1 share would put it over £20m :wink:


#20

:+1: