Skip to content

Instantly share code, notes, and snippets.

@oginga
oginga / import_module_plpython.md
Last active February 14, 2019 22:50
Importing third party(including your own) python modules on PL/Python

Problem

I needed to perfom some linear programming calculations with my local Postgres installation whenever there was change(insert/update) in any row for my events table. This prompted the creation of a trigger function(NB: the example below is a UDF that doesn't return a trigger) and binding it to the table.I edited a dummy function to test if my third party module pulp was actually being imported by the PL/Python embedded interpreter.The lib was installed on my systemwide local site-package dir /home//.local/lib/python2.7/site-packages - Elementary Juno and visible on pip freeze

	CREATE OR REPLACE FUNCTION pyversion() RETURNS text AS $$
	import sys,os
@oginga
oginga / server.py
Last active November 30, 2017 10:29
Poll to Webhook for python telegram bot.This is a simple hack for those who develop python telegram bots and are unable to test their local servers using webhook.The below script(updater.py) polls the telegram server and makes a request to a running django localhost server(server.py).
import os,sys,json
from telegram import Bot,Update
from telegram.ext import Dispatcher,Filters,CommandHandler,MessageHandler
from django.conf import settings
from django.views.decorators.csrf import csrf_exempt
from django.conf.urls import url
from django.core.wsgi import get_wsgi_application
from django.shortcuts import render