Esempio n. 1
0
	def onUpdate():
		entryList = List[Entry]()

		if NetworkInterface.GetIsNetworkAvailable():
			# f = open('text.txt', 'w')
			try:
				request = WebRequest.Create(Uri("http://www.gaitameonline.com/rateaj/getrate"))
				response = None
				stream = None
				streamReader = None

				try:
					response = request.GetResponse()
					stream = response.GetResponseStream()
					streamReader = StreamReader(stream)
					r = streamReader.ReadToEnd()
					jsonDictionary = JsonDecoder.decode(r)
					# f.write(r)
					# f.write("\n\n\n")

					if jsonDictionary is not None and clr.GetClrType(Dictionary[String, Object]).IsInstanceOfType(jsonDictionary) and jsonDictionary.ContainsKey("quotes") and jsonDictionary["quotes"] is not None and clr.GetClrType(Array).IsInstanceOfType(jsonDictionary["quotes"]):
						vfx = "C:\\Program Files (x86)\\tamiyasu_talk\\vrx.exe"
						for obj in jsonDictionary["quotes"]:
							ask = None
							bid = None
							currencyPairCode = None
							entry = Entry()

							if obj is not None and clr.GetClrType(Dictionary[String, Object]).IsInstanceOfType(obj):
								currencyPairCode = obj["currencyPairCode"]
								if (("EUR" in currencyPairCode) or ("GBP" in currencyPairCode) or ("USD" in currencyPairCode))and ("JPY" in currencyPairCode):
									currencyPairCode = currencyPairCode.replace("EUR", u"ユーロ").replace("GBP", u"ポンド").replace("USD", u"ドル").replace("JPY", "")
									ask = obj["ask"]
									bid = obj["bid"]
									val = String.Format("{0}: {1} / {2}", currencyPairCode, ask, bid)
									# f.write(val)
									# f.write("\n")

									entry.Title = val
									entry.Description = val
									entryList.Add(entry)
									# MessageBox.Show(val, currencyPairCode)
									if File.Exists(vfx):
										Process.Start(vfx,val)

						Script.Instance.Alert(entryList)

				finally:
					if streamReader is not None:
						streamReader.Close()

					if stream is not None:
						stream.Close()
			
					if response is not None:
						response.Close()

			except Exception, e:
				Trace.WriteLine(e.clsException.Message)
				Trace.WriteLine(e.clsException.StackTrace)
Esempio n. 2
0
	def onUpdate():
		if NetworkInterface.GetIsNetworkAvailable():
			try:
				response = None
				stream = None
				
				try:
					response = request.GetResponse()
					stream = response.GetResponseStream()
					doc = XmlDocument()
					doc.Load(stream)
				
					for itemXmlNode in doc.GetElementsByTagName("item"):
						entry = Entry()
						epicenter = None
						maxLevel = None
			
						for xmlNode in itemXmlNode.ChildNodes:
							if xmlNode.Name.Equals("link"):
								entry.Resource = Uri(xmlNode.InnerText)
							elif xmlNode.Name.Equals("description"):
								entry.Description = xmlNode.InnerText
							elif xmlNode.Name.Equals("tenkiJP:earthquake"):
								for attribute in xmlNode.Attributes:
									if attribute.Name.Equals("epicenter"):
										epicenter = attribute.Value
									elif attribute.Name.Equals("max_level"):
										maxLevel = attribute.Value
									elif attribute.Name.Equals("outbreak_datetime"):
										entry.Created = entry.Modified = DateTime.Parse(attribute.Value)
						
						if epicenter is not None:
							if String.IsNullOrEmpty(maxLevel):
								maxLevel = "N/A"

							if CultureInfo.CurrentCulture.Equals(CultureInfo.GetCultureInfo("ja-JP")):
								entry.Title = String.Format("震度{0} - {1}", maxLevel, epicenter)
							else:
								entry.Title = String.Format("Intensity {0} - {1}", maxLevel, epicenter)

							entryList.Add(entry)

				finally:			
					if stream is not None:
						stream.Close()
			
					if response is not None:
						response.Close()

			except Exception, e:
				Trace.WriteLine(e.clsException.Message)
				Trace.WriteLine(e.clsException.StackTrace)
Esempio n. 3
0
	def onUpdate():
		entryList = List[Entry]()

		if NetworkInterface.GetIsNetworkAvailable():
			try:
				request = WebRequest.Create(Uri("http://indexes.nikkei.co.jp/nkave"))
				response = None
				stream = None
				streamReader = None

				try:
					response = request.GetResponse()
					stream = response.GetResponseStream()
					streamReader = StreamReader(stream)
					r = streamReader.ReadToEnd()

					pattern1 = re.compile("top-nk225-value\">([,.0-9]+)[^0-9]")
					pattern2 = re.compile("top-nk225-differ\">([-+,.0-9]+)[^0-9]")
					m1 = pattern1.search(r)
					m2 = pattern2.search(r)
					if m1:
						entry = Entry()
						val = String.Format(u"日経平均株価 {0} ({1})", m1.group(1), m2.group(1))
						entry.Title = val
						entry.Description = val
						entryList.Add(entry)
						
						vfx = "C:\\Program Files (x86)\\tamiyasu_talk\\vrx.exe"
						if File.Exists(vfx):
							Process.Start(vfx,val)

						Script.Instance.Alert(entryList)

				finally:
					if streamReader is not None:
						streamReader.Close()

					if stream is not None:
						stream.Close()
			
					if response is not None:
						response.Close()

			except Exception, e:
				Trace.WriteLine(e.clsException.Message)
				Trace.WriteLine(e.clsException.StackTrace)
Esempio n. 4
0
def onTick(timer, e):
	global ts

	ts = ts.Add(timer.Interval)
	entry = Entry()
	
	if CultureInfo.CurrentCulture.Equals(CultureInfo.GetCultureInfo("ja-JP")):
		entry.Title = String.Format("予定の{0}分前になりました", Math.Abs(ts.Minutes).ToString())
	else:
		if Math.Abs(ts.Minutes) == 1:
			entry.Title = String.Format("{0} minute remaining", Math.Abs(ts.Minutes).ToString())
		else:
			entry.Title = String.Format("{0} minutes remaining", Math.Abs(ts.Minutes).ToString())

	if ts.TotalMilliseconds >= 0:
		timer.Stop()
		ts = TimeSpan.Zero

		if CultureInfo.CurrentCulture.Equals(CultureInfo.GetCultureInfo("ja-JP")):
			entry.Title = "予定の時間になりました"
		else:
			entry.Title= "Time expired"

	entryList = List[Entry]()
	entryList.Add(entry)
	Script.Instance.Alert(entryList)
Esempio n. 5
0
    def onUpdate():
        if NetworkInterface.GetIsNetworkAvailable():
            try:
                response = None
                stream = None

                try:
                    response = request.GetResponse()
                    stream = response.GetResponseStream()
                    doc = XmlDocument()
                    doc.Load(stream)

                    for entryXmlNode in doc.GetElementsByTagName("entry"):
                        entry = Entry()

                        for xmlNode in entryXmlNode.ChildNodes:
                            if xmlNode.Name.Equals("title"):
                                entry.Title = xmlNode.InnerText
                            elif xmlNode.Name.Equals("issued"):
                                entry.Created = DateTime.Parse(
                                    xmlNode.InnerText)
                            elif xmlNode.Name.Equals("modified"):
                                entry.Modified = DateTime.Parse(
                                    xmlNode.InnerText)
                            elif xmlNode.Name.Equals("link"):
                                for attribute in xmlNode.Attributes:
                                    if attribute.Name.Equals("href"):
                                        entry.Resource = Uri(attribute.Value)
                            elif xmlNode.Name.Equals("author"):
                                for childXmlNode in xmlNode.ChildNodes:
                                    if childXmlNode.Name.Equals("name"):
                                        entry.Author = childXmlNode.InnerText

                        entry.Image = Uri(
                            "http://www.google.co.jp/options/icons/gmail.gif")
                        entryList.Add(entry)

                finally:
                    if stream is not None:
                        stream.Close()

                    if response is not None:
                        response.Close()

            except Exception, e:
                Trace.WriteLine(e.clsException.Message)
                Trace.WriteLine(e.clsException.StackTrace)
Esempio n. 6
0
    def onUpdate():
        if NetworkInterface.GetIsNetworkAvailable():
            try:
                response = None
                stream = None

                try:
                    response = request.GetResponse()
                    stream = response.GetResponseStream()
                    doc = XmlDocument()
                    doc.Load(stream)

                    for itemXmlNode in doc.GetElementsByTagName("item"):
                        entry = Entry()
                        epicenter = None
                        maxLevel = None

                        for xmlNode in itemXmlNode.ChildNodes:
                            if xmlNode.Name.Equals("link"):
                                entry.Resource = Uri(xmlNode.InnerText)
                            elif xmlNode.Name.Equals("description"):
                                entry.Description = xmlNode.InnerText
                            elif xmlNode.Name.Equals("tenkiJP:earthquake"):
                                for attribute in xmlNode.Attributes:
                                    if attribute.Name.Equals("epicenter"):
                                        epicenter = attribute.Value
                                    elif attribute.Name.Equals("max_level"):
                                        maxLevel = attribute.Value
                                    elif attribute.Name.Equals(
                                            "outbreak_datetime"):
                                        entry.Created = entry.Modified = DateTime.Parse(
                                            attribute.Value)

                        if epicenter is not None:
                            if String.IsNullOrEmpty(maxLevel):
                                maxLevel = "N/A"

                            if CultureInfo.CurrentCulture.Equals(
                                    CultureInfo.GetCultureInfo("ja-JP")):
                                entry.Title = String.Format(
                                    "震度{0} - {1}", maxLevel, epicenter)
                            else:
                                entry.Title = String.Format(
                                    "Intensity {0} - {1}", maxLevel, epicenter)

                            entryList.Add(entry)

                finally:
                    if stream is not None:
                        stream.Close()

                    if response is not None:
                        response.Close()

            except Exception, e:
                Trace.WriteLine(e.clsException.Message)
                Trace.WriteLine(e.clsException.StackTrace)
Esempio n. 7
0
	def onUpdate():
		if NetworkInterface.GetIsNetworkAvailable():
			try:
				response = None
				stream = None
				
				try:
					response = request.GetResponse()
					stream = response.GetResponseStream()
					doc = XmlDocument()
					doc.Load(stream)
				
					for entryXmlNode in doc.GetElementsByTagName("entry"):
						entry = Entry()
			
						for xmlNode in entryXmlNode.ChildNodes:
							if xmlNode.Name.Equals("title"):
								entry.Title = xmlNode.InnerText
							elif xmlNode.Name.Equals("issued"):
								entry.Created = DateTime.Parse(xmlNode.InnerText)
							elif xmlNode.Name.Equals("modified"):
								entry.Modified = DateTime.Parse(xmlNode.InnerText)
							elif xmlNode.Name.Equals("link"):
								for attribute in xmlNode.Attributes:
									if attribute.Name.Equals("href"):
										entry.Resource = Uri(attribute.Value)
							elif xmlNode.Name.Equals("author"):
								for childXmlNode in xmlNode.ChildNodes:
									if childXmlNode.Name.Equals("name"):
										entry.Author = childXmlNode.InnerText
			
						entry.Image = Uri("http://www.google.co.jp/options/icons/gmail.gif")
						entryList.Add(entry)

				finally:			
					if stream is not None:
						stream.Close()
			
					if response is not None:
						response.Close()

			except Exception, e:
				Trace.WriteLine(e.clsException.Message)
				Trace.WriteLine(e.clsException.StackTrace)
Esempio n. 8
0
		def onExecute():
			if NetworkInterface.GetIsNetworkAvailable():
				try:
					postResponse = None
					postResponseStream = None
					postStreamReader = None
					statusCode = None
					isPosted = False

					try:
						postRequestStream = None

						try:
							bytes = Encoding.ASCII.GetBytes(String.Empty)
							postRequestStream = postRequest.GetRequestStream()
							postRequestStream.Write(bytes, 0, bytes.Length)
						
						finally:
							if postRequestStream is not None:
								postRequestStream.Close()

						postResponse = postRequest.GetResponse()

						if postResponse.StatusCode == HttpStatusCode.OK:
							postResponseStream = postResponse.GetResponseStream()
							postStreamReader = StreamReader(postResponseStream)

							jsonDictionary = JsonDecoder.decode(postStreamReader.ReadToEnd())

							if jsonDictionary is not None and clr.GetClrType(Dictionary[String, Object]).IsInstanceOfType(jsonDictionary) and jsonDictionary.ContainsKey("id"):
								isPosted = True

						statusCode = postResponse.StatusCode.ToString()
					
					finally:
						if postStreamReader is not None:
							postStreamReader.Close()

						if postResponseStream is not None:
							postResponseStream.Close()

						if postResponse is not None:
							postResponse.Close()

					if isPosted:
						updateResponse = None
						updateStream = None
						updateStreamReader = None

						try:
							updateResponse = updateRequest.GetResponse()
							updateStream = updateResponse.GetResponseStream()
							updateStreamReader = StreamReader(updateStream)
							jsonDictionary = JsonDecoder.decode(updateStreamReader.ReadToEnd())

							if jsonDictionary is not None and clr.GetClrType(Dictionary[String, Object]).IsInstanceOfType(jsonDictionary) and jsonDictionary.ContainsKey("data") and jsonDictionary["data"] is not None and clr.GetClrType(Array).IsInstanceOfType(jsonDictionary["data"]):
								for obj in jsonDictionary["data"]:
									if obj is not None and clr.GetClrType(Dictionary[String, Object]).IsInstanceOfType(obj):
										entry = Entry()
										userId = None

										if obj.ContainsKey("id"):
											if obj["id"] is not None:
												array = obj["id"].Split('_')

												if array.Length == 2:
													entry.Resource = Uri(String.Format("http://www.facebook.com/{0}/posts/{1}", array[0], array[1]))
													
										if obj.ContainsKey("from"):
											if obj["from"] is not None:
												if clr.GetClrType(Dictionary[String, Object]).IsInstanceOfType(obj["from"]):
													entry.Author = obj["from"]["name"]

													if obj["from"].ContainsKey("id"):
														userId = obj["from"]["id"]
																
										if obj.ContainsKey("created_time"):
											if obj["created_time"] is not None:
												entry.Created = DateTime.Parse(obj["created_time"])

										if obj.ContainsKey("updated_time"):
											if obj["updated_time"] is not None:
												entry.Modified = DateTime.Parse(obj["updated_time"])

										if obj.ContainsKey("message"):
											if obj["message"] is not None:
												title = Regex.Replace(obj["message"], "[\r\n]", String.Empty, RegexOptions.CultureInvariant)

												if title.Length > 100:
													title = title.Remove(100, title.Length - 100)

												entry.Title = title

										if entry.Resource is not None and userId is not None:
											entry.Image = Uri(String.Format("https://graph.facebook.com/{0}/picture?access_token={1}", userId, urlEncode(accessToken)))
											entryList.Add(entry)

						finally:
							if updateStreamReader is not None:
								updateStreamReader.Close()

							if updateStream is not None:
								updateStream.Close()
				
							if updateResponse is not None:
								updateResponse.Close()

					return statusCode

				except WebException, e:
					return e.Response.StatusCode.ToString()

				except Exception, e:
					Trace.WriteLine(e.clsException.Message)
					Trace.WriteLine(e.clsException.StackTrace)
Esempio n. 9
0
		def onDispatch(task):
			global httpListener

			if task.Exception is None:
				httpListener.GetContextAsync().ContinueWith[List[Entry]](Func[Task[HttpListenerContext], List[Entry]](onDispatch), TaskContinuationOptions.LongRunning).ContinueWith(Action[Task[List[Entry]]](onCompleted), context)

				try:
					if task.Result.Request.HttpMethod.Equals(WebRequestMethods.Http.Post) and task.Result.Request.Url.AbsolutePath.Equals("/alert"):
						if task.Result.Request.ContentType.Equals("application/json"):
							stream = None
							streamReader = None
					
							try:
								stream = task.Result.Request.InputStream
								streamReader = StreamReader(stream)
								jsonArray = JsonDecoder.decode(streamReader.ReadToEnd())

								if jsonArray is not None and clr.GetClrType(Array).IsInstanceOfType(jsonArray):
									entryList = List[Entry]()

									for obj in jsonArray:
										if clr.GetClrType(Dictionary[String, Object]).IsInstanceOfType(obj):
											entry = Entry()

											if obj.ContainsKey("resource") and clr.GetClrType(String).IsInstanceOfType(obj["resource"]):
												entry.Resource = Uri(obj["resource"])

											if obj.ContainsKey("title") and clr.GetClrType(String).IsInstanceOfType(obj["title"]):
												entry.Title = obj["title"]

											if obj.ContainsKey("description") and clr.GetClrType(String).IsInstanceOfType(obj["description"]):
												entry.Description = obj["description"]
										
											if obj.ContainsKey("author") and clr.GetClrType(String).IsInstanceOfType(obj["author"]):
												entry.Author = obj["author"]

											if obj.ContainsKey("created") and clr.GetClrType(String).IsInstanceOfType(obj["created"]):
												entry.Created = DateTime.Parse(obj["created"])

											if obj.ContainsKey("modified") and clr.GetClrType(String).IsInstanceOfType(obj["modified"]):
												entry.Modified = DateTime.Parse(obj["modified"])

											if obj.ContainsKey("image") and clr.GetClrType(String).IsInstanceOfType(obj["image"]):
												entry.Image = Uri(obj["image"])

											if obj.ContainsKey("tags") and clr.GetClrType(Array).IsInstanceOfType(obj["tags"]):
												for o in obj["tags"]:
													if clr.GetClrType(String).IsInstanceOfType(o):
														entry.Tags.Add(o)

											entryList.Add(entry)

										else:
											task.Result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.BadRequest)
												
											return None

									return entryList

								else:
									task.Result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.BadRequest)
				
							finally:
								if streamReader is not None:
									streamReader.Close()

								if stream is not None:
									stream.Close()

						else:
							task.Result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.UnsupportedMediaType)

					else:
						task.Result.Response.StatusCode = Convert.ToInt32(HttpStatusCode.Forbidden)
				
				except Exception, e:
					Trace.WriteLine(e.clsException.Message)
					Trace.WriteLine(e.clsException.StackTrace)

				finally:
Esempio n. 10
0
        def onDispatch(task):
            global httpListener

            if task.Exception is None:
                httpListener.GetContextAsync().ContinueWith[List[Entry]](
                    Func[Task[HttpListenerContext], List[Entry]](onDispatch),
                    TaskContinuationOptions.LongRunning).ContinueWith(
                        Action[Task[List[Entry]]](onCompleted), context)

                try:
                    if task.Result.Request.HttpMethod.Equals(
                            WebRequestMethods.Http.Post
                    ) and task.Result.Request.Url.AbsolutePath.Equals(
                            "/alert"):
                        if task.Result.Request.ContentType.Equals(
                                "application/json"):
                            stream = None
                            streamReader = None

                            try:
                                stream = task.Result.Request.InputStream
                                streamReader = StreamReader(stream)
                                jsonArray = JsonDecoder.decode(
                                    streamReader.ReadToEnd())

                                if jsonArray is not None and clr.GetClrType(
                                        Array).IsInstanceOfType(jsonArray):
                                    entryList = List[Entry]()

                                    for obj in jsonArray:
                                        if clr.GetClrType(Dictionary[
                                                String,
                                                Object]).IsInstanceOfType(obj):
                                            entry = Entry()

                                            if obj.ContainsKey(
                                                    "resource"
                                            ) and clr.GetClrType(
                                                    String).IsInstanceOfType(
                                                        obj["resource"]):
                                                entry.Resource = Uri(
                                                    obj["resource"])

                                            if obj.ContainsKey(
                                                    "title"
                                            ) and clr.GetClrType(
                                                    String).IsInstanceOfType(
                                                        obj["title"]):
                                                entry.Title = obj["title"]

                                            if obj.ContainsKey(
                                                    "description"
                                            ) and clr.GetClrType(
                                                    String).IsInstanceOfType(
                                                        obj["description"]):
                                                entry.Description = obj[
                                                    "description"]

                                            if obj.ContainsKey(
                                                    "author"
                                            ) and clr.GetClrType(
                                                    String).IsInstanceOfType(
                                                        obj["author"]):
                                                entry.Author = obj["author"]

                                            if obj.ContainsKey(
                                                    "created"
                                            ) and clr.GetClrType(
                                                    String).IsInstanceOfType(
                                                        obj["created"]):
                                                entry.Created = DateTime.Parse(
                                                    obj["created"])

                                            if obj.ContainsKey(
                                                    "modified"
                                            ) and clr.GetClrType(
                                                    String).IsInstanceOfType(
                                                        obj["modified"]):
                                                entry.Modified = DateTime.Parse(
                                                    obj["modified"])

                                            if obj.ContainsKey(
                                                    "image"
                                            ) and clr.GetClrType(
                                                    String).IsInstanceOfType(
                                                        obj["image"]):
                                                entry.Image = Uri(obj["image"])

                                            if obj.ContainsKey(
                                                    "tags") and clr.GetClrType(
                                                        Array
                                                    ).IsInstanceOfType(
                                                        obj["tags"]):
                                                for o in obj["tags"]:
                                                    if clr.GetClrType(
                                                            String
                                                    ).IsInstanceOfType(o):
                                                        entry.Tags.Add(o)

                                            entryList.Add(entry)

                                        else:
                                            task.Result.Response.StatusCode = Convert.ToInt32(
                                                HttpStatusCode.BadRequest)

                                            return None

                                    return entryList

                                else:
                                    task.Result.Response.StatusCode = Convert.ToInt32(
                                        HttpStatusCode.BadRequest)

                            finally:
                                if streamReader is not None:
                                    streamReader.Close()

                                if stream is not None:
                                    stream.Close()

                        else:
                            task.Result.Response.StatusCode = Convert.ToInt32(
                                HttpStatusCode.UnsupportedMediaType)

                    else:
                        task.Result.Response.StatusCode = Convert.ToInt32(
                            HttpStatusCode.Forbidden)

                except Exception, e:
                    Trace.WriteLine(e.clsException.Message)
                    Trace.WriteLine(e.clsException.StackTrace)

                finally: