예제 #1
0
def download_tts(file_path, text, settings):
    with WebClient() as wc:
        url = "https://translate.google.com/translate_tts?ie=UTF-8&tl={1}&client=tw-ob&q={0}".format(
            HttpUtility.UrlEncode(text), settings["lang"])
        wc.Headers["Referer"] = "http://translate.google.com/"
        wc.Headers["User-Agent"] = "stagefright/1.2 (Linux;Android 5.0)"
        wc.DownloadFile(url, file_path)
def getTimesheetsFromZendesk(templateQueryContext):
	# --- setup zendesk settings ---
	serverURL = "https://yourZendeskHost"
	userName = "******"
	token = "yourZendeskToken"
	# --- setup zendesk settings ---

	clr.AddReference("System.Web")
	clr.AddReference("System.Net.Http")
	clr.AddReference("Newtonsoft.Json")
	from System.Text import Encoding
	from Newtonsoft.Json.Linq import JObject
	from System.Collections.Generic import List
	from System.Web import HttpUtility
	from System.Net.Http import HttpClient
	from System.Net.Http.Headers import AuthenticationHeaderValue

	user = Context.SelectSingleWithParams({
		"Query": "From U In UserDetail Where U.UserDetailUuid = @UserDetailUuid Select U",
		"@UserDetailUuid": templateQueryContext.UserDetailUuid
	})

	query = HttpUtility.UrlEncode("type:ticket updated:" + templateQueryContext.BeginTime.ToString("yyyy-MM-dd") + " assignee:" + user.Username) 
	queryURL = serverURL + "/api/v2/search.json?query=" + query

	credentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(userName + "/token:"+ token));

	modelEntity = ModelEntity({ "Name": "Result" })
	modelEntity.Properties.Add(TextProperty({ "Name": "Description" }))
	modelEntity.Properties.Add(TextProperty({ "Name": "ResultTitle" }))
	modelEntity.Properties.Add(TextProperty({ "Name": "ResultSortOrder" }))

	result = List[EntityObject]()

	with HttpClient() as client:
		client.DefaultRequestHeaders.Authorization = AuthenticationHeaderValue("Basic", credentials)
		response = client.GetAsync(queryURL).Result
		response.EnsureSuccessStatusCode()

		text = response.Content.ReadAsStringAsync().Result
		json = JObject.Parse(text)

		for item in json.results:
			id = str(item.id)
			name = str(item.via.source["from"].name)
			subject = str(item.subject)
			status = str(item.status)

			entity = modelEntity.CreateEntityObject()
			entity.Description = "#" + id + ": " + subject + " (" + name + ", " + status + ")"
			entity.ResultTitle = entity.Description
			entity.ResultSortOrder = entity.Description
			result.Add(entity)

	templateQueryContext.Templates = result
예제 #3
0
    def __str__(self):
        ''' create string respresentation of individual request '''

        # default to json format for get queries
        if self.method == OdataRequest.Method.GET and "format" not in self.query.keys(
        ):
            self.query["format"] = "json"

        # request
        requestUrl = self.url
        for key in self.query.keys():
            if self.query.keys()[0] == key:  # is first
                requestUrl += "?"
            requestUrl += "${key}={value}".format(key=key,
                                                  value=HttpUtility.UrlEncode(
                                                      self.query[key]))
            if self.query.keys()[-1] != key:  # not last
                requestUrl += "&"
        request = " ".join([self.method, requestUrl, "HTTP/1.1"])

        # headers
        if self.method != OdataRequest.Method.GET:
            request += "\nContent-Type: " + self.contentType
        if self.contentId is not None:
            request += "\nContent-ID: " + self.contentId
        if self.body is not None:
            request += "\nContent-Length: " + str(len(self.body))
        if self.method != OdataRequest.Method.GET:
            request += "\nAccept: " + self.accept

        # body
        if self.body is not None:
            request += "\n\n" + self.body
        else:
            request += "\n"
        return request
예제 #4
0
        def search(self, jql):
            clr.AddReference("System.Web")
            from System.Web import HttpUtility
            from System.Net import HttpWebRequest
            from System.IO import StreamReader
            clr.AddReference("Newtonsoft.Json")
            from Newtonsoft.Json import JsonTextReader
            from Newtonsoft.Json.Linq import JObject
            from System import Decimal
            import Newtonsoft.Json
            clr.ImportExtensions(Newtonsoft.Json.Linq)
            usernamepw = Convert.ToBase64String(
                Encoding.UTF8.GetBytes(
                    String.Format("{0}:{1}", self.username, self.password)))

            fieldsparam = String.Join(",", self.requestedFields)
            requestUri = String.Format(
                "{0}rest/api/2/search?jql={1}&fields={2}",
                self.repository.AbsoluteUri, HttpUtility.UrlEncode(jql),
                fieldsparam)
            Logger.Write(LogLevel.Verbose, "Jira.Search: {0}", requestUri)

            request = HttpWebRequest.Create(requestUri)
            request.ContentType = "application/json"

            request.Headers.Add("Authorization", "Basic " + usernamepw)

            request.Method = "GET"
            with request.GetResponse() as response:
                with StreamReader(response.GetResponseStream()) as sr:
                    with JsonTextReader(sr) as jr:
                        result = JObject.Load(jr)
                        issues = result["issues"]

                        items = list()
                        for issue in issues:
                            item = Issue()
                            item.Key = Newtonsoft.Json.Linq.Extensions.Value[
                                String](issue["key"])
                            fields = issue["fields"]
                            item.Updated = Newtonsoft.Json.Linq.Extensions.Value[
                                DateTime](fields["updated"])

                            # transform seconds to hours
                            estimate = Newtonsoft.Json.Linq.Extensions.Value[
                                System.Object](fields["timeoriginalestimate"])

                            if estimate is not None:
                                estimate = Newtonsoft.Json.Linq.Extensions.Value[
                                    Decimal](fields["timeoriginalestimate"])
                                estimate = estimate / (60.0 * 60.0)

                            item.TimeOriginalEstimate = estimate
                            status = fields["status"]
                            item.Status = Newtonsoft.Json.Linq.Extensions.Value[
                                String](status["name"])
                            item.Summary = Newtonsoft.Json.Linq.Extensions.Value[
                                String](fields["summary"])
                            type = fields["issuetype"]
                            item.Type = Newtonsoft.Json.Linq.Extensions.Value[
                                String](type["name"])
                            item.Link = self.repository.ToString(
                            ) + "browse/" + item.Key

                            subTasks = fields["subtasks"]
                            item.SubTaskKeys = System.Linq.Enumerable.Cast[
                                JObject](subTasks).Select(
                                    lambda t: Newtonsoft.Json.Linq.Extensions.
                                    Value[String](t["key"])).ToArray[String]()
                            items.Add(item)

                        return items