├── README.md ├── the-model-bot.py └── get-models.py /README.md: -------------------------------------------------------------------------------- 1 | # theModelBot 2 | Twitter bot. Two scripts are contained, get-models.py downloads images from a website hosting pictures of models, and creates a folder to store them in. the-model-bot.py accesses the twitter API via the tweepy library, and tweets the pictures of models at a set time interval. 3 | -------------------------------------------------------------------------------- /the-model-bot.py: -------------------------------------------------------------------------------- 1 | # themodelbot 2 | 3 | import tweepy as tp 4 | import time 5 | import os 6 | 7 | # credentials to login to twitter api 8 | consumer_key = '' 9 | consumer_secret = '' 10 | access_token = '' 11 | access_secret = '' 12 | 13 | # login to twitter account api 14 | auth = tp.OAuthHandler(consumer_key, consumer_secret) 15 | auth.set_access_token(access_token, access_secret) 16 | api = tp.API(auth) 17 | 18 | os.chdir('models') 19 | 20 | # iterates over pictures in models folder 21 | for model_image in os.listdir('.'): 22 | api.update_with_media(model_image) 23 | time.sleep(3) 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /get-models.py: -------------------------------------------------------------------------------- 1 | # model scraping for themodelbot 2 | 3 | import requests 4 | from bs4 import BeautifulSoup as bs 5 | import os 6 | 7 | # website with model images 8 | url = 'https://www.pexels.com/search/model/' 9 | 10 | # download page for parsing 11 | page = requests.get(url) 12 | soup = bs(page.text, 'html.parser') 13 | 14 | # locate all elements with image tag 15 | image_tags = soup.findAll('img') 16 | 17 | # create directory for model images 18 | if not os.path.exists('models'): 19 | os.makedirs('models') 20 | 21 | # move to new directory 22 | os.chdir('models') 23 | 24 | # image file name variable 25 | x = 0 26 | 27 | # writing images 28 | for image in image_tags: 29 | try: 30 | url = image['src'] 31 | response = requests.get(url) 32 | if response.status_code == 200: 33 | with open('model-' + str(x) + '.jpg', 'wb') as f: 34 | f.write(requests.get(url).content) 35 | f.close() 36 | x += 1 37 | except: 38 | pass 39 | 40 | 41 | 42 | 43 | 44 | 45 | --------------------------------------------------------------------------------