Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Wednesday, 11 February 2015

How do I run a bash command in python 3? topic






Hi I'm trying to learn how to use python. What I want to do it change some of my bash scripts into python 3 scripts as I learn python. I have a bash script that does apt-get update and want to now I would do that in python?

I installed python 3 with apt-get install idle3 to learn python3

found this but I think it is old
import subprocess

def bash_command(cmd):
subprocess.Popen(cmd, shell=True, executable='/bin/bash')

bash_command('a="Apples and oranges" && echo "${a/oranges/grapes}"')

I get this error message in idle3
SyntaxError: multiple statements found while compiling a single statement
with a red line after import subprocess






Tuesday, 10 February 2015

[ubuntu] Lost Panel after executing Aptitude command on Python topic






So guys, I executed the Aptitude to uninstall my python(v2.7) due to some development work. However, i think i typed in something and all my other files were also removed.

Now when i reboot into Ubuntu (v12.04), My desktop has no Panels and I am unable to perform any operations.

The link below shows the errors...

Link : https://www.dropbox.com/sh/763dbcysv...mFQV0ZD7a?dl=0


Furthermore, I have alot of dependency problem.
E.g.

The following packages have unmet dependencies:python-software-properties : Depends: python (< 2.7) but 2.7.3-0ubuntu2 is to be installed
Depends: python-pycurl but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
What is the issue???

Please help....

Regards,
Julius






Sunday, 8 February 2015

Cron won't run Python Twitter Bot topic






It runs perfectly manually and in cron's bash environment - so I'm assuming there might be something about crontab in the OAuth process itself? I have tried running env in cron and pasting the PATH I found there also...

twitter_follow_bot.py

Code:


from twitter import Twitter, OAuth, TwitterHTTPError
import os


# put your tokens, keys, secrets, and Twitter handle in the following variables
OAUTH_TOKEN = "..."
OAUTH_SECRET = "..."
CONSUMER_KEY = "..."
CONSUMER_SECRET = "..."
TWITTER_HANDLE = "..."


# put the full path and file name of the file you want to store your "already followed"
# list in
# OMITTED - ALREADY_FOLLOWED_FILE = "already-followed.csv"


t = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET,
            CONSUMER_KEY, CONSUMER_SECRET))




def search_tweets(q, count=100, result_type="recent"):
    """
        Returns a list of tweets matching a certain phrase (hashtag, word, etc.)
    """


    return t.search.tweets(q=q, result_type=result_type, count=count)


startuprun.py

Code:


from twitter_follow_bot import auto_fav


auto_fav("startup", count=100)


sudo crontab -e (the last line is an alternate tester - today is "7" in cron's calendar..

Code:


PATH=/usr/bin:/bin
SHELL=/usr/bin/bash


*/15 * * * * 1-2 /usr/bin/python /var/www/html/twitter/startuprun.py  >> /tmp/cron.output
*/15 * * * 3-4 /usr/bin/python /var/www/html/twitter/entrepreneurrun.py  >> /tmp/cron.output
*/15 * * * 5-6 /usr/bin/python /var/www/html/twitter/venturecapitalrun.py  >> /tmp/cron.output
*/1 * * * 7 /usr/bin/python /var/www/html/twitter/techrun.py >> /tmp/cron.output
*/1 * * * 7 python /var/www/html/twitter/techrun.py >> /tmp/cron.output


Errors are no longer writing to cron.output so I think it might be on twitters end.

Anyone know of any issues between cron and the authorisation process? Or maybe something else that I've missed? I've also tried putting a shebang for bash, python at the top of crontab but no joy...






Wednesday, 4 February 2015

Non-standard python topic






I want to use this python-binding to CUDA

https://store.continuum.io/cshop/accelerate/

But there is a problem. As the support told me:


Quote:





Anaconda doesn't work with your system python or your system python libraries. Anaconda supersedes it. The Anaconda install changes your path so when you open up a terminal and type python the first and only python and python libraries it sees are in your home directory. (unless you are on windows, that's a different story)

All of these instructions are for linux:
* Install Anaconda from continuum.io/downloads
* You can update libraries directly from the terminal by typing:


conda install <package>


if that fails (as it will for pygtk because there isn't a conda package in the anaconda channel for that yet)
you can look on binstar.org to find the package you want built by the community.


conda install -c https://conda.binstar.org/ska pygtk


Pip installs also work.
pip install <package_name>




So I would like to solve this problem...... I need the community help!!!! Many thanks!!