Tag: python

Django ALLOWED_HOSTS
01/08/2019
After you installed Django and wanted to view it from another local machine you got this error:
DisallowedHost at / Invalid HTTP_HOST header: ‘192.168.3.20’. You may need to add u’192.168.3.20′ to ALLOWED_HOSTS.
I use this to work around it.
Run as:
1 |
python3 manage.py runserver 0:8000 |
Open the settings:
1 |
nano settings.py |
Change and add:
1 2 |
ALLOWED_HOSTS = ['localhost','127.0.0.1'] ALLOWED_HOSTS += ['192.168.3.{}'.format(i) for i in range(256)] |
Now everything and anyone on your local network should have acces to the website.
^that’s also a big warning!
Share the post "Django ALLOWED_HOSTS"

Retrieve data from a .csv and show it a window
23/07/2019
I needed a quick way to show temps from a .csv on a screen.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# # Retrieve the data from the .CSV and show it in a nice window # import matplotlib.pyplot as plt import numpy as np # draw the figure so the animations will work fig = plt.gcf() fig.show() fig.canvas.draw() while True: data = np.genfromtxt('test_data.csv', delimiter=',', dtype=None, skip_header=0, names=('date', 'value')) plt.plot(data['date'], data['value'], color="red") plt.title("Temperatuur") plt.xlabel("tijd") plt.ylabel("Temp") plt.xticks(rotation=90) # Rotate the date text plt.pause(60) # wait 60 seconds before update fig.canvas.draw() |
Share the post "Retrieve data from a .csv and show it a window"
Watch the sky (simple python ftp script)
14/11/2013
So you got the raspberry and the camera board.
With a cronjob you can let it take pictures every few seconds or hour and do something with it. Might be a timelaps video or send it to twitter. In this case I added a simple script to the “RasBotPi” so it can send a picture every hour to this website.
a Simple script will capture a jpg and then send it to this website with python and its ftp library.
1 2 3 4 5 6 7 |
import ftplib # Ftp the image to other website sftp = ftplib.FTP('webserver.com','username','password') # Connect to server fp = open('/home/username/projects/webcam/webcam.jpg','rb') # file to send to server sftp.storbinary('STOR /httpdocs/webcam.jpg', fp) # SStore the file on the server fp.close() # Close sftp.quit() |
Here an example of the snapshot that the camera board takes..
Share the post "Watch the sky (simple python ftp script)"
Show album art in Conky with python script.
05/09/2010
I wanted to show some Album art in conky.
Ofcourse i didnt need to re-invent the wheel so I stumbled upon this forum topic:
Crunchbanglinux::forums::images-in-conky-specifically-rhythmbox-album-art
iggykoopa created a nice script (see here) but because I like the dark feeling of #! I wanted to have the album art in greyscale.
I took his base from: http://crunchbanglinux.org/pastebin/29 and added this part to it: (and an option so you can start it with “conkymusic.py -g”.)
1 2 3 4 |
def grey: image = Image.openhome + "/.album" image = image.convert'L' image.savehome + "/.album", "png" |
You can grab the whole code here: Python CrunchBang Linux Pastebin.
The code in conky:
1 2 |
${execi 10 /home/pieter/.conky/conkymusic.py -g -s 75x75} ${image /home/pieter/.album -p 170,10 -s 75x75} |
Works great here.
Share the post "Show album art in Conky with python script."