Skip to content

Instantly share code, notes, and snippets.

@bgalvao
Last active September 30, 2019 20:26
Show Gist options
  • Select an option

  • Save bgalvao/f59d10229693a3a2a4cb1b7cad7a9d2b to your computer and use it in GitHub Desktop.

Select an option

Save bgalvao/f59d10229693a3a2a4cb1b7cad7a9d2b to your computer and use it in GitHub Desktop.
Fetch random quote from indiehackers.com, as a kickstart to your terminal session (add it to your .bashrc or similar), as if you're loading they're page.
#!/usr/bin/python
import numpy as np
import requests
from colored import fg, bg, attr
# after probing, I found out that these are the possible values
# [0, 140[
url = "https://indie-hackers.firebaseio.com/loadingQuotes/{}.json".format(
np.random.choice(140)
)
r = requests.get(url)
data = r.json()
quote = data['quote']
founder, company = data['byline'].split('of')
print('\n%s"%s"%s%s\n' % (fg(221), quote, attr(7), attr(0)))
print('%s- %sof%s%s\n' % (fg('dark_green_sea'), founder, company, attr(0)))
#print(fg('dark_green_sea') + '(www.indiehackers.com)' + attr(0) + '\n')
@bgalvao
Copy link
Copy Markdown
Author

bgalvao commented Sep 30, 2019

So uh, three dependencies, all pip installable to your system python.

@dmlittle
Copy link
Copy Markdown

Doesn't have color output (got lazy and didn't want to look up the color escape sequences ๐Ÿ˜…) but here's a bash (+ jq) version:

#!/bin/sh

quote_num=$(($RANDOM%140))
url=https://indie-hackers.firebaseio.com/loadingQuotes/${quote_num}.json

data=$(curl -s $url)

quote=$(echo $data | jq .quote)
byline=$(echo $data | jq -r .byline)

echo $quote
echo "- " $byline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment