fgaublog

string.find(s, sub[, start[, end]]) ... und so zeugs ...

 

 

django 1.7 - update django database to reflect changes in existing models

25. April 2015 14:09 | categories: databases, python, django

python manage.py makemigrations app name
python manage.py migrate

anyway, it's time to upgrade my projects to django 1.8.


django - allow only requests from specific IP

3. März 2015 17:58 | categories: programming, python, django

for a django project i needed a exception for the rss feed requests. they are only allowed to request for a set of specific IP addresses. django's feed syndication framework is the base, and i have added a little snippet for receiving the remote address. the HttpRequest.META method reads all available HTTP header informations and for that case we read REMOTE_ADDR. only ip addresses in ip_allow are ready to receive the feed objects.

from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse
from policebeat.models import NewsItem

class LatestEntriesFeed(Feed):
    title = "Police beat site news"
    link = "/sitenews/"
    description = "Updates on changes and additions to police beat central."

    def get_object(self, request):
        self.ip_current = request.META['REMOTE_ADDR']
        self.feed = action.upper()

    def items(self):
        ip_allow = ['222.222.222.222', '111.111.111.111', '127.0.0.1']
        if not self.ip_current in ip_allow:
            self.feed = "not_allowed"
            return empty feed

        return NewsItem.objects.order_by('-pub_date')[:5]

    def item_title(self, item):
        return item.title

    def item_description(self, item):
        return item.description

    # item_link is only needed if NewsItem has no get_absolute_url method.
    def item_link(self, item):
        return reverse('news-item', args=[item.pk])

31c3 is over

9. Januar 2015 22:17 | categories: events

the pyneo project is very happy to be part of the 31c3 in hamburg. our small team had a lot of fun with hard and software. samsung phones, a special tizen phone, gps tracker with gsm modems, bus pirates, serial consol finder workshop and so on. cool guys on a cool loacation with very interesting talks, thats the spirit during entertaining congress. i like it and i'm looking forward to the next year. 31c3 a new dawn!

tizen phone

light and beamer installation 1

light and beamer installation 2


android http post to django server

30. November 2014 01:16 | categories: programming, python, android, django

for an android/server gps project, i have need to send some data to a server. in my case a django server. on my android app a HttpPost sends data to http://epydial.pyneo.org/receiver/. The HttpPost is embedded in a AsyncTask. After sucessfully post, a toast message is genereated.

private class PostAsyncTask extends AsyncTask {
        @Override
        protected Double doInBackground(String... params) {
            // TODO Auto-generated method stub
            postData(params[0]);
            return null;
        }

        protected void onPostExecute(Double result){
            Toast.makeText(getApplicationContext(), "successfully logged", Toast.LENGTH_SHORT).show();
        }

        @SuppressWarnings("unused")
        public void postData(String valueIWantToSend) {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://epydial.pyneo.org/receiver/");
            try {
                // create a list to store HTTP variables and their values
                List nameValuePairs = new ArrayList();
                // add an HTTP variable and value pair
                nameValuePairs.add(new BasicNameValuePair("myHttpData", valueIWantToSend));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                // send the variable and value, in other words post, to the URL
                HttpResponse response = httpclient.execute(httppost);
            } catch (ClientProtocolException e) {
                // process exception
            } catch (IOException e) {
                // process exception
            }
        }
    }

the receiver method on my django server:

@csrf_exempt
def receiver(request):
    if request.method == 'POST':
        with open('/var/www/qblog/static/xml/test.xml', 'w') as f:
            f.write(request.POST.get('myHttpData'))
            f.close()
further information about the @csrf_exempt decorator you can find here. the rest of the receiver method is self-explanatory. all my data, in that case longitude and latitude are saved in the myHttpData array and are written to a xml file for further web processing.


autumn 2014 in berlin

8. November 2014 20:13 | categories: other

this image is composed of 2 photos, and showing the gartenstrasse in northerly and southerly direction. and it is not the berlin wall.


guitar hero

12. Juli 2014 01:05 | categories: music

zakk wylde from black label society presented new songs from the new album 'Catacombs Of The Black Vatican' in berlin 'huxleys neue welt' on july 1st. the show and the sound was impressive. the berlin chapter says thank you for a great show!


adminer - alternative to phpmyadmin

29. Juni 2014 22:45 | categories: databases

more security, more performance, better interface, which promises the database management tool adminer. the single php script can handle mysql, postgresql, sqlite, ms sql, mongodb and other. i have tested the functionality, and it does what it promise. a cool tool!


python and the facebook api

12. Juni 2014 20:35 | categories: programming, python

to run this example, you need at first a facebook app. this video shows the simple setup. pick the App ID and App Secret from there and insert it in the python code below.

the program returns all comments from a single facebook post. you can limited the request and you can change the facebook post ID. the graph api explorer is the perfect starting point to learn more about the fb api.

the last part is for error handling and simple json parsing to get all the interesting information.

#!/usr/bin/env python          
# -*- coding: utf-8 -*-

from json import loads         
from urllib2 import Request, urlopen, URLError, HTTPError

APPID = "XXXXXXXXXXXXXXXXXX"   
APPSECRET = "XXXXXXXXXXXXXX"   
FBPOSTID = "588013424601016"   
LIMIT = 3000
GRAPH_URL = "https://graph.facebook.com/%s/comments?access_token=%s|%s&limit=%d" % (
                FBPOSTID,      
                APPID,
                APPSECRET,     
                LIMIT)         
try:
    response = urlopen(GRAPH_URL)

except HTTPError as e:         
    print 'The server couldn\'t fulfill the request.'
    print 'Error code: ', e.code    

except URLError as e:
    print 'We failed to reach a server.'
    print 'Reason: ', e.reason 

else:
    decoded = loads(response.read())
    for item in decoded['data']:
        print '%s,%s,%s' % (
            item['created_time'],
            item['from']['name'],
            item['message'])

what a night

11. Juni 2014 10:45 | categories: music


here we go!

4. Juni 2014 17:59 | categories: music