WSGI mod, Python, Django, Celery and a nice fella virtualenv

Here I’ll show how to use Python (3.8.0 in the current example, but legit for latest 3.+ versions, not for os.name == ‘NT’) and virtualenv to setup WGSI enabled website on Django (or any) with implemented Celery + Flower + RabbitMQ. This example is my own path used for automated test framework: Octopus (not available now, but have dev branch opened: Lobster) Here only configurations and setup for Python 3.8.0, virtualenv, WSGI, Django, Celery (worker and beat services), Flower and that’s it. Later I’ll show Django + Celery configuration when they run together (sort of). You may want to install Python at first: Read When your modern and fancy python is installed, we’ll make a virtual environment for our website.Short Read more…

Django fast hints

Here some fast hints to remember: Migration: cd ~/myproject python manage.py makemigrations python manage.py migrate   Alias /static/ “/var/www/smm_tools/site/”   Read more…

How tired I am of Google way how get API tokens

You must: Create application and take its id and secret. Make a GET request to send secret and id with needed scopes of access. Obtain TEMPORARY access token and refresh token (first lives about 3000 – 5000 sec, the second can probably live infinite) Use this access token to GET something through REST, check if this token is not expires already. You want to GET something ELSE? First check if your token is not expired, then if expired – use refresh token to get NEW TEMPORARY token. Do something else. Nice turn google! You are the best of masters of creating shitcode. Before starting real work on google API and my own project with Google Drive I’ll learn pythons “requests” perfectly,Short Read more…

Google Drive API

Thanks to this guy, whose question and gist helps me understand the google api and requests for it to get access for google drive. http://stackoverflow.com/questions/22534959/access-google-drive-api-in-python-whithout-google-api-python-client-installed-a I found everything! If anybody will be confused like me: Get your google drive your_api_key from here: https://console.developers.google.com/apis/credentials?project=[your_project] in section with name “API keys” – or you can generate it by pushing “New Credentials” -> “API key” Also you can get your token with google “quick start” even for python3: https://developers.google.com/drive/v2/web/quickstart/python Your token will be saved on system user’s folder (C:/Users/user/.credentials) or (/root/.credentials) for Linux if you run it under “root”. The token is in “access_token” key value. Then you can generate request, but at first check this: http://docs.python-requests.org/en/master/user/quickstart/#custom-headers And this is working example toShort Read more…

Django static files

How to find where def. static stores? [root@test smm_py]# python3 manage.py findstatic css/base.css admin/js/core.js No matching file found for ‘css/base.css’. Found ‘admin/js/core.js’ here: /usr/local/lib/python3.4/site-packages/django/contrib/admin/static/admin/js/core.js Then move it into the folder you need. Then update django’s.conf file: Alias /static/ “/var/www/smm_tools/site/” And check the settings.py: 103 # Static files (CSS, JavaScript, Images) 104 # https://docs.djangoproject.com/en/1.8/howto/static-files/ 105 106 STATIC_URL = ‘/static/’ https://docs.djangoproject.com/en/1.8/howto/static-files/   Read more…

Django + Python3.4 + Mysql(MariaDB)

Just hint for future me: [root@test smm_py]# vim settings.py [root@test smm_py]# python manage.py makemigrations import MySQLdb as Database ImportError: No module named ‘MySQLdb’ django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named ‘MySQLdb’ [root@test smm_py]# pip install mysql-python3 Collecting mysql-python Downloading MySQL-python-1.2.5.zip (108kB) 100% || 110kB 812kB/s ImportError: No module named ‘ConfigParser’ —————————————- Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-build-t64nwwtb/mysql-python [root@test smm_py]# easy_install mysql-python ImportError: No module named ‘ConfigParser’ ImportError: No module named ‘ConfigParser’ [root@test smm_py]# pip3 install ConfigParser Collecting ConfigParser _KEYCRE = re.compile(ur”%\(([^)]+)\)s”) SyntaxError: invalid syntax —————————————- [root@test smm_py]# pip3.4 install –allow-external mysql-connector-python mysql-connector-python Collecting mysql-connector-python Downloading http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.0.4.zip (277kB) 100% || 278kB 3.7MB/s Successfully built mysql-connector-python Successfully installed mysql-connector-python-2.0.4 [root@test smm_py]# vim /smm_py/settings.py 76 77 DATABASESShort Read more…

Django + apache2 + mod_wsgi

This is conf file to allow apache run Django applications. # Web site at /var/www/smm_tools # Python scripts at /var/www/smm_tools/smm_py #LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so <VirtualHost *:80> ServerName smm.www.trianglesis.org.ua ServerAlias www.smm.www.trianglesis.org.ua ServerAdmin it@www.trianglesis.org.ua DocumentRoot /var/www/smm_tools/ ErrorLog “|/usr/sbin/rotatelogs /var/log/smm_tools/cargo.error.%Y-%m-%d.log 86400” CustomLog “|/usr/sbin/rotatelogs /var/log/smm_tools/cargo.access.%Y-%m-%d.log 86400” combined ServerSignature On Alias /css/ “/var/www/smm_tools/site/css” Alias /js/ “/var/www/smm_tools/site/js/” Alias /templates/ “var/www/smm_tools/site/templates/” Alias /fonts/ “/var/www/smm_tools/fonts/” #WSGIScriptAlias / /var/www/smm_tools/smm_tools.wsgi #WSGIPythonPath /var/www/smm_tools <Directory /var/www/smm_tools/smm_py/smm_py> <Files wsgi.py> Require all granted </Files> </Directory> WSGIDaemonProcess smm_tools python-path=/var/www/smm_tools/smm_py:/usr/local/lib/python3.4/site-packages/ WSGIProcessGroup smm_tools WSGIScriptAlias / /var/www/smm_tools/smm_py/smm_py/wsgi.py </VirtualHost> Use these links: https://www.digitalocean.com/community/tutorials/how-to-run-django-with-mod_wsgi-and-apache-with-a-virtualenv-python-environment-on-a-debian-vps https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-ubuntu-14-04 https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ Don’t forget to use correct IPs – domains, and addresses. Especially if proxy pass is used.     Read more…

Allow Apache run python scripts

This is a simple ex. to allow apache run .py # Python site at /var/www/py_site LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so <VirtualHost *:80> ServerName test.www.trianglesis.org.ua ServerAlias www.www.trianglesis.org.ua ServerAdmin test@test.com DocumentRoot /var/www/py_site/ <Directory /var/www/py_site> Order allow,deny Require all granted Allow from all </Directory> <Directory /var/www/py_site/cgi-bin> Options +ExecCGI Require all granted Allow from all Options +ExecCGI AddHandler cgi-script .cgi .pl .py AddHandler cgi-script .py </Directory> </VirtualHost>     Read more…

ADDM Comunity Edition install and configure

Here I’ll describe how to install and configure ADDM – Atrium Discovery and dependency Mapping virtual appliance and allow it to run as I want it to run. You can request a free trial on bmc site and they will email you link where you can find virtual appliances.   Tasks are: change root password allow ‘root’ – to log in from everywhere and do anything disable SElinux disable ipv6 proto disable firewall add custom IP, not DHCP allow ftp into appliance install webmin for addm aplliance for easy manage use custom port for UI http note: sometimes apache proxy to multiple addm on port 80 – can produce UI errors. I do not know how handle it, even afterShort Read more…

Going deeper with Python or HTMLParser and Vkontakte randomizer comes back!

Hello, for anybody who read this blog. Last time I’m trying to parse saved HTML page to get Vkontakte ids and randomly select one of them each time: here and here. Now I’ll try to go deeper and use different way to extract data from life webpage without sawing it to the folder with python script. For my opinion, using some googling I should use this: http://docs.python-guide.org/en/latest/scenarios/scrape/ http://stackoverflow.com/questions/2081586/web-scraping-with-python later I will add some more KB The small plan: Add URL of parsed page: to txt file – and them get it from file to python to console, after python request to user Get all found ids and save it list to file ids.csv optionally with Name+id or just id if names will produceShort Read more…