Skip to content

Instantly share code, notes, and snippets.

@thomasjpfan
Last active August 29, 2015 13:57
Show Gist options
  • Save thomasjpfan/9353854 to your computer and use it in GitHub Desktop.
Save thomasjpfan/9353854 to your computer and use it in GitHub Desktop.
Simple script for posting to social pages
#!/usr/local/bin/python3
import argparse
import re
import subprocess
def is_valid_link(link):
match = re.compile(r"^https?://.+")
link_match = match.findall(link)
if link_match:
return link_match
else:
msg = "{} is not a valid link".format(link)
raise argparse.ArgumentTypeError(msg)
parser = argparse.ArgumentParser(description="Post to social networks")
parser.add_argument('message', type=str, nargs=1)
parser.add_argument('-l', '--link', type=is_valid_link)
args = parser.parse_args()
f_cli = ['/usr/local/bin/fbcmd']
t_cli = ['/usr/local/opt/ruby/bin/t', 'update']
message = args.message[0]
if args.link:
link = args.link[0]
f_cli = f_cli + ['FEEDLINK', link, message]
output = "{1} {0}".format(link, message)
t_cli = t_cli + [output]
else:
f_cli = f_cli + ["STATUS", message]
t_cli = t_cli + [message]
print(' '.join(f_cli))
print(' '.join(t_cli))
subprocess.call(f_cli)
subprocess.call(t_cli)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment