using random pics with Twython
<p>I'm using Twython to make a bot who post random image from a folder, here is the code !</p>

<pre><code>from twython import Twython
import glob
import random

app_key = "XXX"
app_secret = "XXX"
oauth_token = "XXX" 
oauth_token_secret = "XXX"
twitter = Twython(app_key, app_secret, oauth_token, oauth_token_secret)

def RandomImageTwitt(folder):
        #Takes the folder where your images are as input
        images = glob.glob(folder + "*")
        image_open = open(images[random.randint(0,len(images))-1])
        #Tweeting
        image_ids = twitter.upload_media(media=image_open)
        twitter.update_status(status='hello this is a status', media_ids=image_ids['media_id'])

 RandomImageTwitt("/home/Pi/Bots/Pictures/")
</code></pre>

<p>Ok, and when i use python script.py, it return this error :</p>

<pre><code>Traceback (most recent call last):
  File "script.py", line 20, in &lt;module&gt;
  RandomImageTwitt("/home/Pi/Bots/Pictures/")
File "script.py", line 14, in RandomImageTwitt
  image_open = open(images[random.randint(0,len(images))-1])
IndexError: list index out of range
</code></pre>

<p>I'm beginner in Python, if that can help, all my files are stored like this : 1.jpg, 2.jpg, 3.jpg... every files are in jpg and the list begin from 1.</p>

<p>Thanks !</p>