strife's devLog

Tag: python

SVN Log Generator based on user history

I faced with the problem of writing reports. Most of cases what I do at work is the same as what I pushed to the repository. If you still use SVN (no idea why though) then you can use this script to show all your comments in svn log in this week. It shows logs only in current week.

log-generator.py

Usage:

Example Output:

Share

300px-Python-logo-notext.svgConverting Large XLS, XLSX files to CSV using Python

I was in troubles to convert big xlsx files in PHP because there is no such a library that could make it as good as possible. What I’ve found out were libraries that could manage xls / xlsx files but it took a lot of time and performance was horrible.

So, not spending too much time to think about it I’ve figured out to leave PHP and try to make it in Python. What I wanted to achive was converting xls files into csv and handle it in PHP.

In Python we got xlrd library that enables us to make this “crazy” thing. Here it is: https://pypi.python.org/pypi/xlrd. You can install it using pip, such like:

But for my case it was better to use VirtualENV which is better solution when someday you’d like to move your software somewhere and you forgot about installing all those stuff. However, each way you chose would be fine till it’s working.

After installing required items all you need is to run the script that converts xls into csv. I have already written simple script that can make it. Please find code below and save it to your local system setting the proper permissions right (chmod +x filename).

convert_xls.py

If you have a python script created in your local filesystem the next step would be manage it from PHP. And this is most simplest solution. Using exec, system, or shell_exec solves the problem.

OR in command line.

I know that solution is not really clean but it works. To have it more elegant I would suggest to create some kind of service in Python that handles it in a good way. I will think about it …

Note: I have also fixed issue with Long numbers in XLS.

Update
If you need to parse big XLS, XLSX files I would suggest not to make in in PHP. Just parse this using JAVA where PHP would be used only for UI.

Any questions, let me know. Please find comment form below.

Share

Paypal-logoUsing PayPal WPP (Express Checkout) with Django

A couple days ago I had to deal with PayPal WPP (Express Checkout) for some application and I found the module in the GitHub: https://github.com/dcramer/django-paypal.

Which works great but it was very hard to find how to set up the PayPal Payment Pro with Express Checkout method and fill customer forms in PayPal. I decided to find how to deal with it and I figured out how to do that.

After all developing stuff related to install this module to your django aplication you need to know how to send requests to PayPal using this method. And here’s the answer:
Read the full article »

Share