Last active
February 9, 2018 15:32
-
-
Save jamenlang/9fe0178812e0047d733f746eef626494 to your computer and use it in GitHub Desktop.
custom hangups script for setting status
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Example of using hangups to set presence.""" | |
import asyncio | |
import hangups | |
import urllib.request | |
from common import run_example | |
async def set_presence(client, args): | |
url = 'https://sportsball.net/status.php' | |
request = urllib.request.Request(url) | |
response = urllib.request.urlopen(request) | |
array = response.read().decode('utf-8').split(',') | |
#response expected to look like 3FA,Seated,1518188410,Valid | |
current_status = array[1] | |
if 'seated' in current_status.lower(): | |
print ("found 'seated' in %s", current_status) | |
current_status = 'SEATED!' | |
with open('previous_status.txt', 'r') as myfile: | |
previous_status=myfile.read().replace('\n', '') | |
if previous_status is current_status: | |
exit() | |
with open("previous_status.txt", "w") as text_file: | |
text_file.write(current_status) | |
#print("setting status to %s", current_status) | |
request = hangups.hangouts_pb2.SetPresenceRequest( | |
request_header=client.get_request_header(), | |
status_message=( | |
hangups.hangouts_pb2.StatusMessageSpec( | |
status_message=[ | |
hangups.hangouts_pb2.ChatMessageSpec( | |
segment=[ | |
hangups.hangouts_pb2.Segment( | |
type=hangups.hangouts_pb2.SEGMENT_TYPE_TEXT, | |
text=current_status, | |
formatting=hangups.hangouts_pb2.Formatting( | |
bold=False, | |
italic=False, | |
strikethrough=False, | |
underline=False, | |
), | |
), | |
] | |
), | |
] | |
) | |
) | |
) | |
await client.set_presence(request) | |
if __name__ == '__main__': | |
run_example(set_presence) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment