Skip to content

Instantly share code, notes, and snippets.

View kimthostrup's full-sized avatar

Kim Thostrup kimthostrup

View GitHub Profile
@kimthostrup
kimthostrup / disks_lshw.py
Created May 17, 2018 12:16 — forked from amitsaha/disks_lshw.py
Use lshw -xml to find the disk details
#!/usr/bin/env python
# Parse disk:* from lshw -xml
"""
Sample Output:
ATA Disk Hitachi HDS72105 /dev/sda
Disk Space: 500107862016
Sector size: 512
@kimthostrup
kimthostrup / connectbox-influx.py
Created May 14, 2018 18:51
Quick, dirty and crappy script to pull DOCSIS connection info from a UPC Connect Box (Compal CH7465LG) and push it to influxdb. Should run as a systemd service. Requires this: https://github.com/ties/compal_CH7465LG_py
#!/usr/bin/env python3
import argparse
import pprint
import os
import sys
import datetime
import signal
from time import sleep
from lxml import etree
@kimthostrup
kimthostrup / orwell.py
Created May 14, 2018 18:18 — forked from olf42/orwell.py
Fetches number of currently connected listeners from status.xml of icecast2 streaming server and pushes it to InfluxDB (at least v.0.10)
#!/usr/bin/env python3
import requests
import sys
import xml.etree.ElementTree as ET
import datetime
# ICECAST RELATED CONSTANTS
STATS_URL = "http://<URL>"
ICECAST_USER = "<USER>"
@kimthostrup
kimthostrup / xml.py
Created May 14, 2018 13:40
example for parsing xml
import xml.etree.ElementTree as ET
import urllib.request as MYURL
# tree = ET.parse('song.xml')
# rss = tree.getroot()
# for element in rss.findall('.channel/song'):
# print(element.attrib.get('sname'))
# print(element.findtext('title'))
# print(element.findtext('singer'))
kmaURL = "http://www.kma.go.kr/weather/forecast/mid-term-rss3.jsp?stnId=109"
@kimthostrup
kimthostrup / UFW_ban_country.md
Created January 19, 2018 22:04 — forked from jasonruyle/UFW_ban_country.md
UFW to block countries
#!/usr/local/bin/python
import os
import plivo
import sys
from time import strftime
if not os.path.isdir(PATH):
sys.exit()
#!/bin/bash
date=`date +%Y-%m-%d`
RETENTION_PERIOD="7"
HEADER="Backup data"
remove_oldfiles(){
echo "Removing directory $1 files older than $RETENTION_PERIOD days" | wall
find $1 -type f -mtime +$2 -exec rm '{}' \;
}
BACKUPDIR="/disk0/svn_backup/001/"
@kimthostrup
kimthostrup / nio.py
Created December 1, 2015 21:29 — forked from sobanvuex/nio.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
from os import listdir
import json
net = '/sys/class/net'
stat = net + '/{}/statistics/{}x_bytes'
interfaces = filter(lambda x: 'eth' in x, listdir(net))
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
@app.route('/index')
def index(chartID = 'chart_ID', chart_type = 'bar', chart_height = 350):
chart = {"renderTo": chartID, "type": chart_type, "height": chart_height,}
series = [{"name": 'Label1', "data": [1,2,3]}, {"name": 'Label2', "data": [4, 5, 6]}]
title = {"text": 'My Title'}