<commit_before>from django.shortcuts import render

# Create your views here.

'''
from django.http import HttpResponse
def index(req):
	return HttpResponse('<h1>hello world</h1>')
'''

from django.shortcuts import render_to_response
from subprocess import *
from django.http import HttpResponse

class App(object):
	def __init__(self):
		self.music = "off"
		self.cmd_out = ""
		self.light = "off"
		self.tem_hum = ""

	def update_music_status(self):
		if cmp(self.music, "off") == 0:
			print "music start..."
			self.music = "on"
			cmd = "/home/pi/music/play.py"
			args = cmd.split(" ")
			self.music_proc = Popen(args)
		else:
			print "music stop..."
			self.music = "off"
			Popen.terminate(self.music_proc)

	def post_weibo(self, content):
		cmd = "/home/pi/post_weibo/post.py" + "+"\
			+ "%s    --From Raspberry"%(content)
		args = cmd.split("+")
		print "post weibo..."
		Popen(args)

	def ir_tv(self, key):
		tv_map = {"Power":"KEY_POWER", "Mute":"KEY_MUTE", "OK":"KEY_OK", "Ch+":"KEY_UP",\
			"Ch-":"KEY_DOWN", "Vol+":"KEY_VOLUMEUP", "Vol-":"KEY_VOLUMEDOWN"}
		if not key in tv_map:
			print "error: %s" %(key)

		print "send tv key: %s" %(tv_map[key])
		cmd = "/home/pi/tv/send_tv_key.sh" + " " + tv_map[key]
		args = cmd.split(" ")
		Popen(args)

	def switch_light(self):
		cmd = "/home/pi/rcswitch-pi/send.sh"
		args = cmd.split(" ")
		Popen(args)
		if cmp(self.light, "off") == 0:
			self.light = "on"
		else:
			self.light = "off"

	def get_tem_hum(self):
		cmd = "/home/pi/dht11/dht11.sh"
		args = cmd.split(" ")
		print args
		try:
			p = Popen(args=args, stdout=PIPE, stderr=PIPE)
			self.tem_hum = p.stdout.read()
		except:
			self.tem_hum = "get data error"

	def exec_command(self, command):
		args = command.split(" ")
		if command == "clear":
			self.cmd_out = ""
			return
		try:
			p = Popen(args=args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
			self.cmd_out = p.stdout.read()
		except:
			self.cmd_out = "command error"



my_app = App()

def index(req):
	global my_app
	print req.POST
	
	if req.POST.has_key('weibo'):
		print "weibo"
		content = req.POST['weibo_content']
		my_app.post_weibo(content)<commit_msg>modify the path of executing modules<commit_after>from django.shortcuts import render

# Create your views here.

'''
from django.http import HttpResponse
def index(req):
	return HttpResponse('<h1>hello world</h1>')
'''

from django.shortcuts import render_to_response
from subprocess import *
from django.http import HttpResponse

class App(object):
	def __init__(self):
		self.music = "off"
		self.cmd_out = ""
		self.light = "off"
		self.tem_hum = ""

	def update_music_status(self):
		if cmp(self.music, "off") == 0:
			print "music start..."
			self.music = "on"
			cmd = "/home/pi/music/play.py"
			args = cmd.split(" ")
			self.music_proc = Popen(args)
		else:
			print "music stop..."
			self.music = "off"
			Popen.terminate(self.music_proc)

	def post_weibo(self, content):
		cmd = "/home/pi/post_weibo/post.py" + "+"\
			+ "%s    --From Raspberry"%(content)
		args = cmd.split("+")
		print "post weibo..."
		Popen(args)

	def ir_tv(self, key):
		tv_map = {"Power":"KEY_POWER", "Mute":"KEY_MUTE", "OK":"KEY_OK", "Ch+":"KEY_UP",\
			"Ch-":"KEY_DOWN", "Vol+":"KEY_VOLUMEUP", "Vol-":"KEY_VOLUMEDOWN"}
		if not key in tv_map:
			print "error: %s" %(key)

		print "send tv key: %s" %(tv_map[key])
		cmd = "/home/pi/pi_modules/module.py" + " " + "send_ir"
		args = cmd.split(" ")
		Popen(args)

	def switch_light(self):
		cmd = "/home/pi/pi_modules/module.py" + " " + "send_rc"
		args = cmd.split(" ")
		Popen(args)
		if cmp(self.light, "off") == 0:
			self.light = "on"
		else:
			self.light = "off"

	def get_tem_hum(self):
		cmd = "/home/pi/pi_modules/module.py" + " " + "dht11"
		args = cmd.split(" ")
		print args
		try:
			p = Popen(args=args, stdout=PIPE, stderr=PIPE)
			self.tem_hum = p.stdout.read()
		except:
			self.tem_hum = "get data error"

	def exec_command(self, command):
		args = command.split(" ")
		if command == "clear":
			self.cmd_out = ""
			return
		try:
			p = Popen(args=args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
			self.cmd_out = p.stdout.read()
		except:
			self.cmd_out = "command error"



my_app = App()

def index(req):
	global my_app
	print req.POST
	
	if req.POST.has_key('weibo'):
		print "weibo"
		content = req.POST['weibo_content']
		my_app.post_weibo(content)
{'fraction_non_alphanumeric': 0.17552334943639292, 'fraction_numerical': 0.00322061191626409, 'mean_word_length': 3.5338894681960373, 'pattern_counts': {'":': 16, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '769007', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1717, 'n_words': 368}