Posts Categorized: python

Python Threads Querying CouchDB

With a list of 500,000 CouchDB endpoints to hit for info I wanted to speed up the process. There are multiple ways to do that but queues and threads worked fine for me. The script reads in a list from the file input.txt , then uses that to retrieve a list of documents from an… Read more »

Gitlab API and Python

To start, create a config file with your Gitlab personal token: vi ~/.python-gitlab.cfg With contents similar to below: [global] default = gitlab ssl_verify = true timeout = 5 [gitlab] url = https://gitlab.com private_token = 1234ABCD1234ABCD api_version = 4 next create a directory and a python virtualenv: bashmkdir ./code/python/testpython3 -m venv envsource env/bin/activatepip3 install requests python-gitlab… Read more »

Bash to Python – Playing with CSV

In the past I have been too willing to use bash scripts for grepping and awking CSV files. The code snippet below is a starter for doing similar with python and while far from perfect, demonstrates calling another system command and manipulating strings:

Rename Files with Python

Simple wee python script for renaming files in a directory. I had a bunch of mp4 files that had a reference code at the end rather than the front so renaming to put the reference code at the front would keep them in order e.g. myfile-m6-03.mp4 to become 6-03-myfile-m6-03.mp4 #!/usr/bin/env python from os import rename… Read more »

Querying Zookeeper from Python

Install the prerequisites. Below works for Debian-based distros such as Ubuntu/Mint: apt-get install libzookeeper-mt-dev Install python libraries: pip install zkpython pykeeper Example code below shows making a connection, getting the names of some child nodes and pulling info from each of those child nodes: import pykeeper import json client = pykeeper.ZooKeeper(‘192.168.1.2:2181’) client.connect() coords = client.get_children(‘/druid/coordinator/_COORDINATOR’)… Read more »

Install Python Linters in Atom

I installed the relevant Python packages first e.g. sudo apt-get install flake8 python3-flake8 python3-pep8 python-pep8-naming python3-setuptools pylint3 Then on the Atom menu use: Edit > Preferences then search for atom packages such as flake8, pep8, pep257 and pylint: Then click the install button. After restarting style advice is shown in the editor:    

PhidgetBoard with Raspberry Pi and Tripwire

I very luckily got landed with a: Phidgets Board 8/8/8 (1018) Lanbao PR18S-TM10DNO Photoelectric Tripwire Sensor (3525) I wired the Tripwire sensor to the Phidget board as described in the wiring diagram and as shown in the video: I connected the USB cable from the Phidgets Board to the USB port on a Raspberry Pi… Read more »

Fabric: Getting Started Tutorial

Hopefully this may help someone else out there who is looking for a good excuse to use Fabric in anger. I install Fabric on my local Ubuntu desktop using: sudo apt-get install fabric With Fabric installed I created a new directory for playing around and inside that folder created a file named fabfile.py as follows:… Read more »

Beginning Python on Ubuntu

Ninja IDE Python Ubuntu

I am using Ubuntu 12.10 but with Gnome Fallback session rather than Unity. I was testing out Python by creating a little program to notify if the input year was a leap year or not. I found Ninja IDE useful but had to Edit > Preferences and set the Python path to python3 as shown… Read more »