Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ##########################
- ##~REDDIT KARMA GRABBER~##
- ## v1.2 using curl not ##
- ## lynx for beter comp- ##
- ## -atibility. NOTE: ##
- ## THIS SCRIPT WILL NOT ##
- ## WORK ON A NON-LINUX ##
- ## OPERATING SYSTEM. ##
- ##----------------------##
- ##~~~~~2012 xereeto~~~~~##
- ##########################
- #checks if the script was invoked with a redditor as an argument, if not it
- #asks for one.
- if [ -z "$1" ]; then
- read -p "Which redditor would you like to look up?>" REDDITOR
- else
- REDDITOR=$1
- fi
- #SUPER-HAPPY-FUNTIME-EASTER-EGG!
- #yes I know it's easy to decode, but what the hell.
- if [[ "${REDDITOR,,}" == `echo "eGVyZWV0bwo=" | base64 -d` ]]; then
- MESSAGE=`echo "RUFTVEVSIEVHRyEgVGhhbmtzIGZvciB1c2luZyBteSBzY3JpcHQhCg==" | base64 -d`
- echo -e "\e[1;32m"
- echo "****************************************"
- echo "${MESSAGE}"
- echo "****************************************"
- echo -e "\e[00m"
- fi
- #</easteregg>
- #code to get the json for the redditor
- I_CAN_HAZ_INFO=$(curl --silent --fail --location "http://reddit.com/user/$REDDITOR/about.json")
- #check if redditor exists
- IS_REAL=$(echo "$I_CAN_HAZ_INFO" | grep link_karma)
- if [ -z "$IS_REAL" ]; then
- echo -e "\e[1;31mERROR:\e[00m redditor \"$REDDITOR\" not found."
- exit 1
- fi
- #inserts line breaks where the commas are so I can grep the list
- I_CAN_HAZ_INFO=$(echo "$I_CAN_HAZ_INFO" | tr "," "\n")
- #first and foremost, get the redditor's name with correct capitalization
- REDDITOR=$(echo "$I_CAN_HAZ_INFO" | grep "\"name\":")
- REDDITOR=${REDDITOR//\"/}
- REDDITOR=${REDDITOR:7}
- #gets the timestamp the account was created
- REDDIT_TIME=$(echo "$I_CAN_HAZ_INFO" | grep created_utc)
- REDDIT_TIME=${REDDIT_TIME:16}
- #converts the timestamp to a proper date
- REDDIT_TIME="$(date -ud @$REDDIT_TIME +%c)"
- #gets age of the account in days
- let DIFF=(`date +%s -d now`-`date +%s -d "$REDDIT_TIME"`)/86400
- #self explanatory
- MYD="$DIFF days"
- if [ $DIFF -ge 30 ]; then
- #gets account age in months if $DIFF >= 30 days
- let DIFF=$DIFF/30
- MYD="$DIFF months"
- if [ $DIFF -ge 12 ]; then
- #gets account age in years if $DIFF >= 12 months
- let DIFF=$DIFF/12
- MYD="$DIFF years"
- fi
- fi
- #finds link karma
- LINK_K=$(echo "$I_CAN_HAZ_INFO" | grep link_karma)
- LINK_K=${LINK_K:15}
- #inserts a thousands separator to make it look nice.
- LINK_K=$(printf "%'d" $LINK_K)
- echo
- echo "$REDDITOR has:"
- echo -e " $LINK_K \e[1;31mlink karma\e[00m"
- #finds comment karma
- COMMENT_K=$(echo "$I_CAN_HAZ_INFO" | grep comment_karma)
- COMMENT_K=${COMMENT_K:18}
- #inserts a thousands separator to make it look nice.
- COMMENT_K=$(printf "%'d" $COMMENT_K)
- echo -e " $COMMENT_K \e[1;36mcomment karma\e[00m"
- echo -e "and has been a redditor for \e[1;33m${MYD}.\e[00m"
- #searches for reddit gold.
- echo
- GOLD=$(echo "$I_CAN_HAZ_INFO" | grep "\"is_gold\": true")
- if [ -z "$GOLD" ]; then
- echo -e "$REDDITOR \e[1;31mdoes not\e[00m have reddit gold."
- else
- echo -e "$REDDITOR \e[1;32mdoes\e[00m have reddit gold."
- fi
- echo
- #############################
- ## for best results, place ##
- ## in your PATH and call ##
- ## the script "karma". ##
- #############################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement