Skip to content

Instantly share code, notes, and snippets.

@blha303
blha303 / rarepepe.py
Created November 4, 2015 15:34
Such pepe
#!/usr/bin/env python
try:
from urllib import urlopen
except:
from urllib.request import urlopen
from colorama import init
init()
colormap = {
@blha303
blha303 / waitfor
Created October 12, 2015 10:09
Script that waits for the specified process to start before returning
#!/bin/bash
until ps aux | grep -v grep | grep -v "waitfor" | grep "$1" > /dev/null
do
sleep 0.1
done
@blha303
blha303 / getplex.py
Last active October 2, 2015 06:57
Gets plex streaming urls. Pipe into cast.py (https://gist.github.com/blha303/8b100c205b8c35b3c8ce) for best results. List episodes and movies from plex by omitting titles (i.e getplex.py -m "" or getplex.py -s "Bla")
#!/usr/bin/env python2.7
# Now with Plex auth support! Check getplex.py -h
from __future__ import print_function
from plexapi.server import PlexServer
from plexapi.myplex import MyPlexUser
from plexapi.exceptions import NotFound
from urlparse import urlparse
from getpass import getpass
from socket import gethostbyname
@blha303
blha303 / cast.py
Last active October 28, 2015 02:34
Easy mp4 playback for chromecasts from python. no google chrome needed. for people without RAM. Pausing does not currently work for some reason.
#!/usr/bin/env python
# requires pychromecast and probably python 2.7, sorry
import pychromecast
import argparse
def play_video(url, cast):
if cast.media_controller.status.player_state == "PAUSED" or cast.media_controller.status.content_id == url:
cast.media_controller.play()
else:
@blha303
blha303 / aec-canning-2015.py
Last active September 19, 2015 11:39
Scrape and sort results for Canning by-election. Requirements: python 2.7 probably, requests, beautifulsoup4, tabulate
import requests
from bs4 import BeautifulSoup as Soup
from tabulate import tabulate
import sys
headers = ["Candidate", "Party", "Votes", "%", "Swing (%)"]
def get_data():
soup = Soup(requests.get("http://vtr.aec.gov.au/HouseDivisionFirstPrefs-18126-236.htm").text, "html.parser")
for row in soup.findAll('tr', id=lambda x: x and x.startswith("repeaterCandidates")):
@blha303
blha303 / fizzbuzz.py
Last active September 1, 2015 09:32
My second attempt at FizzBuzz (now with less
#!/usr/bin/env python2
from sys import stdout, exit, argv
def main(start, end):
for i in xrange(int(start),int(end)+1):
q = False
if i % 3 == 0:
stdout.write("Fizz")
q = True
if i % 5 == 0:
@blha303
blha303 / lfm_getlyrics.py
Last active August 29, 2015 14:27
Opens a webbrowser with the azlyrics page for the now-playing song
import pylast, webbrowser, re, sys
key = "9eefecb15b3891540eb66748f37bf539"
use = sys.argv[1] if len(sys.argv) > 1 else "blha303"
def strip(string):
return re.sub(r'[\W_]+', '', string.replace("&", " and "))
lfm = pylast.LastFMNetwork(api_key=key, username=use)
track = lfm.get_user(use).get_now_playing()
@blha303
blha303 / config.php
Created June 10, 2015 03:56
Multiple server support for github.com/delan/lookout http://stats.blha303.biz
<?php
$servers = array("http://stats.home.blha303.biz", "http://stats.web.blha303.biz", "http://stats.ipv6.b303.me", "http://stats.irc.b303.me");
@blha303
blha303 / get-billboard.py
Created June 5, 2015 08:11
Returns a list of tuples for each item in a specified Billboard Top 100 list. Planning a Arch Rollback Machine-style repository for popular music
#!/usr/bin/env python2
from bs4 import BeautifulSoup as Soup
import requests
from collections import namedtuple
from datetime import datetime, timedelta
Song = namedtuple('Song', ['title', 'artist', 'position', 'spotify', 'vevo', 'rdio'])
def billboard(date):
soup = Soup(requests.get("http://www.billboard.com/charts/hot-100/%s" % date).text)
@blha303
blha303 / ytPlaylistToPodcast.py
Last active September 29, 2019 10:46
Generates an iTunes compatible podcast from a Youtube playlist, storing the audio files in a local directory. Could be adapted to store the files in Dropbox or on another media provider if desired | Requires python 2.7, requests, wget, and youtube-dl | Configuration at top of file
#!/usr/bin/env python2
# This file is released as public domain by Steven Smith (blha303) in Apr 2015
# In areas where public domain isn't a thing, I release it under the MIT license.
# Although credit would be nice if you use this in something cool. And email me a link too pls.
import time,os,requests,json,subprocess
from urllib import urlretrieve
DTFORMAT = "%a, %b %d %Y %H:%M:%S +0000" # Do not modify, needs to be at top
playlisturl = "https://www.youtube.com/playlist?list=UU9CuvdOVfMPvKCiwdGKL3cQ"