Python script for sharing Dropbox files on webpages !

Hi there !
I always wanted to have a download list on my wordpress sidebar but I don’t really like I’m using dropbox on ubuntu and I found it really handy so I wrote a python script which is generating public urls of files which are in my Dropbox/Public/downloads. I find out that I can have a rss widget on sidebar so I decided to use it to show my downloads. I choose to generate the rss. My script is simply adding a puburl and the filename (from my dropbox directory) to my delicious bookmarks, than wordpress get’s rss on sidebar widget šŸ˜‰

What you need to use this script:
– Linux with dropbox
– delicious account
– Python (almost on every linux)

Scripts works like this:
Checking if there are any new files in predetermined directory ->; if true: gets filenames and puburls -> send it to with “download” tag (to keep bookmarks in harmony:p) -> (here I’m using it by rss but you can do what you want with it:p)

Here is my code, enjoy ( of course you can download it from sidebar – )
Please post issues in comments or talk to me on gtalk.

# -*- coding: utf-8 -*-
# From author: Stop for a sec on every comment I've posted here, and do what it says  -Tetek
# P.S Add alias to .bashrc to make it faster to run

import urllib2, urllib, commands, dircache, os, struct, time
from stat import *

theurl = ""
#Enter your username and password ( url is constant for everybody)
username = 'tetek'
password = 'xxx'
	passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
	passman.add_password(None, theurl, username, password)
	authhandler = urllib2.HTTPBasicAuthHandler(passman)
	opener = urllib2.build_opener(authhandler)
	print "Incorrect username or password (or just connection fucked up)"

home = os.getenv("HOME")
# Please enter path to folder that you want to upload
path = home + '/Dropbox/Public/downloads/'
files = dircache.listdir(path)

#I'm using tag: download, just simply to get stuff in right order
#'replace' is optional..
def Upload_File_List(i):
	out = commands.getoutput('dropbox puburl ' + path + i)
	paired = { "url": out, "description": i, "tags":"download" ,"replace":"no" }
	data = urllib.urlencode(paired)
	full_url = str(theurl + data)
	upload_it = urllib2.urlopen(full_url)
	print " - " + i + " added!"

#datekeeper keeps the date when this script was last runned
	date_keeper = open("datekeeper.txt", "rb")	
	handler =
	last_update = struct.unpack('i', handler)
#It checks if there are some new files to update
	for x in files:
		check_stat = os.stat(path + x) 
		if int(check_stat[ST_ATIME]) >= int(last_update[0]):
	print "Synchronised"
	for y in files:
	print "Success"

#Saves the current time to the datakeeper.txt I used struct lib to keep int binary
	time_saver = open("datekeeper.txt", "wb")
	current = struct.pack('i', time.time())
	print  "Can't save current time do datekeeper.txt"


4 thoughts on “Python script for sharing Dropbox files on webpages !

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s