title: Python Twitter - Tweepy to post unique content using data from txt or JSON files
body: <p>I have developed a very basic Twitter bot using Python &amp; Tweepy. It is successfully posting a tweet to twitter and I can modify the text in this line of code: <code>response = client.create_tweet( text='Testing' ) </code>to make different tweets</p>
  <p>The full code I am using for this is:</p>
  <pre><code>import tweepy
  
  client = tweepy.Client(consumer_key=&quot;XXXXX&quot;,
                      consumer_secret=&quot;XXXXX&quot;,
                      access_token=&quot;XXXXX&quot;,
                      access_token_secret=&quot;XXXXX&quot;)
  # Create Tweet
  
  response = client.create_tweet(
      text='Testing'
  )
  print(f&quot;https://twitter.com/user/status/{response.data['id']}&quot;)
  </code></pre>
  <p>What I am trying to figure out is how I can code a Bot to randomly read data stored in file(s) and put it altogether to formulate a readable sentence or paragraph a little bit like how a mailmerge works. Here is an example, there are 3 files or 3 values:</p>
  <pre><code>Value1
  Check out this, View this, See this
  Value 2
  product, item, piece
  Value 3
  on our online shop, on our store, on our website
  </code></pre>
  <p>If the bot was able to read and select data at random it could pick any of the data from the files or values in any order, put them together and it would make sense as a sentence or a paragraph</p>
  <p>After researching I see that using text or JSON files might be a possibility. I followed a JSON tutorial and recreated an example that looks like this for text and images:</p>
  <pre><code>[
    {
      &quot;text&quot;: &quot;hi&quot;,
      &quot;image&quot;: &quot;/image1.jpg&quot;
    },
    {
      &quot;text&quot;: &quot;hello&quot;,
      &quot;image&quot;: &quot;/image2.jpg&quot;
    }
  ]
  </code></pre>
  <p>I think I have worked out how to read the JSON file with this code:</p>
  <pre><code>import json
  with open(r&quot;C:\Users\Administrator\Desktop\Python\test.json&quot;) as f:
      info = json.load(f)
  
  randomChoice = random.randrange(len(info))
  print (info[randomChoice])
  </code></pre>
  <p>The thing I am really struggling with is the best way to achieve this and how then to create the code that will post the tweet formulated with the random data it has selected</p>
  <p>This is what I have so far as I attempt to combine Tweepy and the abilty to read in data from the JSON file but I can't get it to work as I don't know how to post the data it has read in to Twitter:</p>
  <pre><code>import tweepy
  import random 
  import json
  with open(r&quot;C:\Users\Administrator\Desktop\Python\test.json&quot;) as f:
      info = json.load(f)
  
  client = tweepy.Client(consumer_key=&quot;XXXXX&quot;,
                      consumer_secret=&quot;XXXXX&quot;,
                      access_token=&quot;XXXXX&quot;,
                      access_token_secret=&quot;XXXXX&quot;)
  # Create Tweet
  
  randomChoice = random.randrange(len(info))
  print (info[randomChoice])
  
  response = client.create_tweet(
      text='NOT SURE HOW TO CODE THIS PART SO TWEEPY POSTS RANDOMLY SELECTED DATA'
  print(f&quot;https://twitter.com/user/status/{response.data['id']}&quot;)
  </code></pre>
  <p>I am brand new to Python and Tweepy so have only a very small understanding but would really appreciate any help on it</p>