Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wget -O - "https://www.worldometers.info/coronavirus/worldwide-graphs/" | grep "Currently Infected" -A 4 | grep data: | sed 's/^[^\[]*//' | sed 's/[]].*}/]/' | ./percentagechange.py
- #!/usr/bin/env python3
- import sys
- import json
- # loop boilerplate
- def skipper(sk):
- def s():
- nonlocal sk
- if (sk > 0):
- sk -= 1
- return True
- return False
- return s
- # load data from stdin and parse as JSON
- sData = ""
- for line in sys.stdin:
- sData += line
- jData = json.loads(sData)
- # convert data and append to output array
- # calculate initial case outside loop
- skip = skipper(1)
- pData = [100] # for sake of argument, 0 --> whatever is a 100% increase
- last = jData[0]
- for i in jData:
- if ( skip() ): continue #don't calculate initial case inside loop
- percentageChange = ( ((i*100)/last) -100 )
- percentageChange = round(percentageChange,2)
- pData.append ( percentageChange)
- last = i
- # print output array, by coincidence this is valid JSON
- print (pData)
Advertisement
Add Comment
Please, Sign In to add comment