-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathwechat_remote.py
61 lines (50 loc) · 1.6 KB
/
wechat_remote.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
#coding=utf-8
# Author: yangxuan([email protected])
# remote for WeChat (based on ItChat: https://github.com/littlecodersh/ItChat)
# modified from this demo(https://github.com/littlecodersh/ItChat/issues/24#issuecomment-228583833)
# you can use this scripts to interact with your computer(such as RaspberryPi)
# it should support most commands you use in terminal, for instance `uname` or `df -h`
import os
import sys
#import subprocess
import itchat
import time
if os.name == 'posix' and sys.version_info[0] < 3:
import subprocess32 as subprocess
else:
import subprocess
help = '''\
WeChat remote:
* download file: diana add url
* download video: youtube-dl url
* online video: mpv url
* & most commands you use in terminal
* help(show this message)\
'''
@itchat.msg_register('Text')
def remote(msg):
#if not msg['FromUserName'] == msg['ToUserName']: return # comment this line if you can't send message to yourself
if msg['Text'] in ['help', u'帮助']:
return help
else:
commands = msg.get('Content', '')
args = commands.split()
# Custom aliases
# if args[0] == 'bilidan':
# args[0] = '/home/pi/BiliDan/bilidan.py'
# if args[0] == 'dad':
# args[0] = '/home/pi/diana/dad'
# if args[0] == 'diana':
# args[0] = '/home/pi/diana/diana'
try:
proc = subprocess.Popen(args,
# shell=True,
# executable='/bin/bash',
# stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
return proc.communicate()[0].strip()
except OSError as e:
return u'Commands/Files not found'
itchat.auto_login(enableCmdQR = True, hotReload = True)
itchat.run()