#!/usr/bin/python3

"""
Author: Robert Cudmore
Date: 20181013
Purpose: Send a Tweet with IP and MAC address of a Raspberry Pi
Install:
	pip3 install tweepy
Usage:
	python3 startuptweet.py 'this is my tweet'
"""

import tweepy
import sys
import socket
import subprocess
from uuid import getnode as get_mac
from datetime import datetime

# Create variables for each key, secret, token
from my_config import hash_tag
from my_config import consumer_key
from my_config import consumer_secret
from my_config import access_token
from my_config import access_token_secret

message = ''
if len( sys.argv ) > 1:
    message = sys.argv[1]


# Set up OAuth and integrate with API
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

#

thetime = datetime.now().strftime('%Y%m%d %H:%M:%S')

ip = subprocess.check_output(['hostname', '--all-ip-addresses'])
ip = ip.decode('utf-8').strip()

hostname = socket.gethostname()

mac = get_mac()
mac = hex(mac)

tweet = thetime + ' ' + hostname + ' ' + ip + ' ' + mac + ' ' + message + ' ' + hash_tag
print('tweeting:', tweet)
api.update_status(status=tweet)

[((33, 7, 33, 57), 'tweepy.OAuthHandler', 'tweepy.OAuthHandler', ({(33, 27, 33, 39): 'consumer_key', (33, 41, 33, 56): 'consumer_secret'}, {}), '(consumer_key, consumer_secret)', False, 'import tweepy\n'), ((35, 6, 35, 22), 'tweepy.API', 'tweepy.API', ({(35, 17, 35, 21): 'auth'}, {}), '(auth)', False, 'import tweepy\n'), ((41, 5, 41, 64), 'subprocess.check_output', 'subprocess.check_output', ({(41, 29, 41, 63): "['hostname', '--all-ip-addresses']"}, {}), "(['hostname', '--all-ip-addresses'])", False, 'import subprocess\n'), ((44, 11, 44, 31), 'socket.gethostname', 'socket.gethostname', ({}, {}), '()', False, 'import socket\n'), ((46, 6, 46, 15), 'uuid.getnode', 'get_mac', ({}, {}), '()', True, 'from uuid import getnode as get_mac\n'), ((39, 10, 39, 24), 'datetime.datetime.now', 'datetime.now', ({}, {}), '()', False, 'from datetime import datetime\n')]