Categories
Uncategorized

Adding new entries to database – Python & MySQL

Checking to see if an entry exists in the database, if not, then add it Currently, in the database we only have two names, ‘Shaniqua’ and ‘Jose’ But the new list of names contains a new person ‘Latifah’. Here is how the db can be updated

Categories
Uncategorized

Selecting and Entering Values – MYSQL

This is how to enter a specific value in a column depending on the value of another column. So we have a table called ‘t_main’ in a database called ‘db_sample’, and it looks something like this. Name Stat1 Status Module 1 23 Module 2 50 Module 3 31 And we want to see if we […]

Categories
Uncategorized

Scraping HTML Generated by JavaScript – Python

Say we want to get some data from stats.cyanogenmod.com. If we were to do a simple wget or curl on the above url, all we would get would be something like this. and within the HTML we can see the following lines this is the bit that generates the actual data we want to download. […]

Categories
Uncategorized

Robots Now Taking Your Orders – Python

There was a post on r/technology about robots potentially taking over from humans if the minimum wage rises. After someone made a comment about robots not being able to spit in your food, u/angryPenguinator replied with a script written in BASIC that describes a robot putting crap on your burger. Now I will try it […]

Categories
Uncategorized

Synchronising two folders – Python

It’s friday…more code for sh*ts and giggles. Limitations and that…. This is a very simple and basic script that will synchronise two directories. It works as long as the files have the same name. It works by measuring the time the files were changed and replacing the older one with the newest one. Again…it will […]

Categories
Uncategorized

Duplicate files, different names – Python

The Problem We have a bunch of files, and some of them have the exact same contents but different names. Here’s what we do. We open the files, read the contents and get the md5. We then compare it and put it all in a dictionary. Example we have three files file1.txt, file2.txt and file3.txt, […]

Categories
Uncategorized

The **kwargs Function Argument – Python

**kwargs can be used for multiple arguments which don’t really have to be specified. All the information is then stored as a dictionary. So if we have a function like this and we run it like this we get this confirming it is a dictionary. We could also call each argument with a loop If […]

Categories
Uncategorized

Pajek to database – Python

This is how you read a pajek file and move it all to a database. This consists of three files, all in the same directory sample.txt – the pajek sample file pajek_rw.py – module that reads the pajek file g2db.py – which moves all the data to a database sample.txt This is what the pajek […]

Categories
Uncategorized

Colouring Clusters – Python

The Graph file The Python bit The Graph

Categories
Uncategorized

ncol2pajek – Python

I’ve just written a very short Python script that will change an ncol graph file to Pajek format. https://github.com/jose187/ncol2pajek Some info on how to use it The ncol File The format of the ncol file will normally be like this The node names should not have any spaces and they should be separated by a […]