Ejemplo n.º 1
0
// ReviewedProduct returns the string of the reviewed thing in a best-effort way.
func (article *Article) ReviewedProduct() string {
	if len(article.Front.Article.Products) == 0 {
		return ""
	}
	if article.Front.Article.Products[0].Source.Value != "" {
		return strings.TrimSpace(sanitize.HTML(article.Front.Article.Products[0].Source.Value))
	}
	// refs. #7111
	if article.Front.Article.Products[0].StringName.Value != "" {
		return strings.TrimSpace(sanitize.HTML(article.Front.Article.Products[0].StringName.Value))
	}
	return ""
}
Ejemplo n.º 2
0
func listenDeploys(lastMarker string, commandMsgs chan<- models.Message, connector models.Connector) (nextMarker string) {
	now := time.Now()
	nextMarker = strconv.FormatInt(now.Unix(), 10) + "000"
	if connector.Debug {
		log.Print("Calling deploy results with last marker: " + lastMarker)
	}
	d := bambooapi.DeployResults(connector.Server, connector.Login, connector.Pass)
	for _, de := range d {
		for _, e := range de.Environmentstatuses {
			buildTime := strconv.FormatInt(e.Deploymentresult.Finisheddate, 10)
			if e.Deploymentresult.ID > 0 && buildTime > lastMarker {
				var m models.Message
				m.In.ConnectorType = connector.Type
				m.In.ConnectorID = connector.ID
				m.In.Tags = connector.Tags
				m.In.Process = false
				m.Out.Text = "Bamboo Deploy " + e.Deploymentresult.Deploymentversion.Planbranchname + " " + e.Deploymentresult.Deploymentversion.Name + " to " + e.Environment.Name + " " + e.Deploymentresult.Deploymentstate
				m.Out.Detail = html.UnescapeString(sanitize.HTML(e.Deploymentresult.Reasonsummary))
				m.Out.Link = "https://" + connector.Server + "/builds/deploy/viewDeploymentResult.action?deploymentResultId=" + strconv.Itoa(e.Deploymentresult.ID)
				if e.Deploymentresult.Deploymentstate == "SUCCESS" {
					m.Out.Status = "SUCCESS"
				} else {
					m.Out.Status = "FAIL"
				}
				commandMsgs <- m
			}
		}
	}
	return nextMarker
}
Ejemplo n.º 3
0
// Public function
// permet d'ajouter un commenaire sur la page tutoriel
func TutorialNouvCommHandler(w http.ResponseWriter, r *http.Request) {
	// Validation des données
	// Si une des variables est vide, la func retourne un "error"
	// ce qui fait afficher un message d'erreur
	if r.PostFormValue("val_commentaire") == "" ||
		r.PostFormValue("val_post_id") == "" ||
		r.PostFormValue("val_auteur_id") == "" ||
		r.PostFormValue("val_auteur_id") == "0" {
		// envoie un message d'erreur
		renderString(w, "error")
	} else {
		// initialise l'objet ForumPost et récupère les données du formulaire
		var tp TutorialPost
		tp.TutorialId, _ = ParseInt(r.PostFormValue("val_post_id"), 0, 64)
		tp.UserId, _ = ParseInt(r.PostFormValue("val_auteur_id"), 0, 64)
		tp.Text = sanitize.HTML(r.PostFormValue("val_commentaire"))
		tp.IsOnline = 1
		tp.Id = tp.Save()
		// permet de récuprérer le nom de l'utilisateur
		var u User
		u.Id = tp.UserId
		u = u.GetById()
		// permet de convertir la date de la personne qui a posté la réponse
		t := time.Now()
		date := t.Format(dateLayout)
		// String qui contient d'abord l'auteur du commentaire
		// puis son commentaire complet, séparés par ":::"
		commData := u.FirstName + " " + u.LastName + ":::" + date + ":::" + tp.Text + ":::" + Itoa(int(tp.Id))
		renderString(w, commData)
	}
}
Ejemplo n.º 4
0
func main() {
	flag.Usage = usage
	flag.Parse()
	args := flag.Args()
	if len(args) != 1 {
		usage()
	}
	url := args[0]
	key := os.Getenv("READABILITY_PARSER_API_KEY")
	if key == "" {
		printMissingKeyMessage()
	}
	parser := readability.NewParserClient(key)
	article, resp, err := parser.Parse(url)
	if resp != nil && resp.StatusCode == 400 {
		usage()
	}
	if err != nil {
		printError(err)
	}
	content := sanitize.HTML(article.Content)
	// remove vertical whitespace
	r := regexp.MustCompile("[\n]{2,}")
	content = r.ReplaceAllString(content, "")
	// remove horizontal whitespace
	content = strings.Replace(content, "  ", "", -1)
	fmt.Println(article.Title + "\n")
	fmt.Println(strings.Replace(strings.TrimSpace(content), "\n", "\n\n", -1))
}
Ejemplo n.º 5
0
func (s *Service) Check(id string) (status string, err error) {
	body, err := s.Downloader(s.URL, id)
	if err != nil {
		return
	}

	if s.Extractor != nil {
		parts := s.Extractor.FindSubmatch(body)
		if parts == nil {
			return "", nil
		}

		status = string(parts[1])
	} else {
		doc, err := gokogiri.ParseHtml(body)
		if err != nil {
			return "", err
		}
		defer doc.Free()

		res, err := doc.Search(s.XPath)
		if err != nil {
			return "", err
		}
		if len(res) < 1 {
			return "", nil
		}

		status = sanitize.HTML(res[0].String())
		status = replacer.ReplaceAllString(status, " ")
		status = strings.TrimSpace(status)
	}

	return
}
Ejemplo n.º 6
0
Archivo: bot.go Proyecto: Pent/bot
func (bot *Bot) Google(query, channel string) {
	r, err := http.Get("http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=1&q=" + query)
	defer r.Body.Close()

	if err != nil {
		log.Println(err)
	}
	if r.StatusCode != http.StatusOK {
		log.Println(r.Status)
	}

	//create a custom struct for the json response
	//somehow Go magically transplants the response data into this
	var google struct {
		ResponseData struct {
			Results []struct {
				TitleNoFormatting string
				Content           string
				URL               string
			}
		}
	}

	//parse response body json to Go
	dec := json.NewDecoder(r.Body)
	dec.Decode(&google)

	//output results to channel
	for _, item := range google.ResponseData.Results {
		//fixme: sending commands
		content := sanitize.Accents(sanitize.HTML(item.Content))
		bot.SendMessage(item.TitleNoFormatting+" "+item.URL+" "+content, channel)
	}
}
Ejemplo n.º 7
0
func listenBuilds(lastMarker string, commandMsgs chan<- models.Message, connector models.Connector) (nextMarker string) {
	var displayOnStart = 0
	url := "https://" + connector.Login + ":" + connector.Pass + "@"
	url += connector.Server + "/builds/plugins/servlet/streams?local=true"
	feed, err := rss.Fetch(url)
	if err != nil {
		log.Print(err)
		return
	}
	for i := len(feed.Items) - 1; i >= 0; i-- {
		if connector.Debug {
			log.Print("Bamboo " + connector.ID + " item #" + strconv.Itoa(i) + " marker " + feed.Items[i].Date.String())
		}
		if lastMarker == "" {
			lastMarker = feed.Items[displayOnStart].Date.String()
		}
		item := feed.Items[i]
		if item.Date.String() > lastMarker {
			status := "NONE"
			if strings.Contains(item.Title, "successful") {
				status = "SUCCESS"
			}
			if strings.Contains(item.Title, "fail") {
				status = "FAIL"
			}
			var m models.Message
			m.In.ConnectorType = connector.Type
			m.In.ConnectorID = connector.ID
			m.In.Tags = connector.Tags
			m.In.Process = false
			m.Out.Text = "Bamboo Build " + html.UnescapeString(sanitize.HTML(item.Title))
			m.Out.Detail = html.UnescapeString(sanitize.HTML(item.Content))
			m.Out.Link = item.Link
			m.Out.Status = status
			commandMsgs <- m
			if i == 0 {
				lastMarker = item.Date.String()
			}
		}
	}
	nextMarker = lastMarker
	return nextMarker
}
Ejemplo n.º 8
0
func callRss(lastMarker string, commandMsgs chan<- models.Message, connector models.Connector) (nextMarker string) {
	var displayOnStart = 0
	if connector.Debug {
		log.Print("Starting rss feed fetch for " + connector.ID)
	}
	feed, err := rss.Fetch(connector.Server)
	if err != nil {
		log.Print(err)
		return
	}
	if connector.Debug {
		log.Print("Feed count for " + connector.ID + ": " + strconv.Itoa(len(feed.Items)))
	}
	for i := len(feed.Items) - 1; i >= 0; i-- {
		if connector.Debug {
			log.Print("Feed " + connector.ID + " item #" + strconv.Itoa(i) + " marker " + feed.Items[i].Date.String())
		}
		if lastMarker == "" {
			lastMarker = feed.Items[displayOnStart].Date.String()
		}
		item := feed.Items[i]
		if item.Date.String() > lastMarker {
			var m models.Message
			m.In.ConnectorType = connector.Type
			m.In.ConnectorID = connector.ID
			m.In.Tags = connector.Tags
			m.In.Process = false
			m.Out.Text = connector.ID + " " + html.UnescapeString(sanitize.HTML(item.Title))
			m.Out.Detail = html.UnescapeString(sanitize.HTML(item.Content))
			m.Out.Link = item.Link
			commandMsgs <- m
			if i == 0 {
				lastMarker = item.Date.String()
			}
		}
	}
	nextMarker = lastMarker
	if connector.Debug {
		log.Print("Next marker for " + connector.ID + ": " + nextMarker)
	}
	return nextMarker
}
Ejemplo n.º 9
0
func (c *connection) reader() {
	for {
		_, message, err := c.ws.ReadMessage()
		if err != nil {
			break
		}
		hello := strings.Split(sanitize.HTML(string(message)), "|")
		ck.Put(hello[0], hello[1])
	}
	c.ws.Close()
}
Ejemplo n.º 10
0
// Make generates excerpt with word length w from input s.
func Make(s string, w int) string {
	scanner := bufio.NewScanner(strings.NewReader(s))
	scanner.Split(bufio.ScanWords)
	count := 0
	var excerpt bytes.Buffer
	for scanner.Scan() && count < w {
		count++
		excerpt.WriteString(scanner.Text() + " ")
	}
	return sanitize.HTML(strings.TrimSpace(excerpt.String()))
}
Ejemplo n.º 11
0
// permet de créer un userProject à partir d'un formulaire HTML
// et permet d'uploader une image associée
// et permet de croper l'image en fonction de sa vignette
func UPCreateAjaxHandler(w http.ResponseWriter, r *http.Request) {

	// création d'un user project
	var up UserProject
	// récupère l'id du user
	UserId, err := ParseInt(r.PostFormValue("id_user"), 0, 64)
	if err != nil {
		// envoie un message d'erreur
		renderString(w, "error")
	}
	up.UserId = UserId
	// crécuprère l'id de la cat
	up.UserProjectCategoryId, err = ParseInt(r.PostFormValue("id_cat"), 0, 64)
	if err != nil {
		// envoie un message d'erreur
		renderString(w, "error")
	}
	// récupère le titre
	up.Title = sanitize.HTML(r.PostFormValue("title"))
	// récupère la description
	up.Description = sanitize.HTML(r.PostFormValue("Description"))
	// permet d'uploader l'image
	up.Url, err = UploadImage(URL_PROJECT_IMAGES, r)
	if err != nil {
		// envoie un message d'erreur
		renderString(w, "error")
	}
	// permet de cropper l'image qui viens d'être uploadée
	err = CropImage(up.Url, 300, 300)
	if err != nil {
		// envoie un message d'erreur
		renderString(w, "error")
	}
	// finit de créer l'objet
	// définit le projet non visible
	up.IsOnline = 0
	// sauvegarde dans la base de donnée
	up.Id = up.Save()
	// retourne l'objet en JSON
	renderJson(w, up)
}
Ejemplo n.º 12
0
Archivo: doc.go Proyecto: x4rMa/webapp
// loadTemplate load template from tpls/%s.tpl
func loadTemplate(Name string) *html.Template {
	funcMap := html.FuncMap{
		"html": func(val interface{}) html.HTML {
			switch value := val.(type) {
			case string:
				{
					return html.HTML(value)
				}
			case html.HTML:
				{
					return value
				}

			default:
				return html.HTML("Unsupported type for HTML pipeline")
			}
		},
		"typo": func(val string) string {
			return typo.Typo(val)
		},
		"striptags": func(val string) string {
			return sanitize.HTML(val)
		},
		// TODO: в разработке
		/*"mod": func(args ...interface{}) interface{} {
		    if len(args) == 0 {
		        return ""
		    }

		    name := args[0].(string)
		    ctx := new(context.Context)

		    if len(args) > 1 {
		        ctx = args[1].(*context.Context)
		    }

		    modules := reflect.ValueOf(modules.Get())
		    mod := modules.MethodByName(name)

		    if (mod == reflect.Value{}) {
		        return ""
		    }

		    inputs := make([]reflect.Value, 0)
		    inputs = append(inputs, reflect.ValueOf(ctx))

		    ret := mod.Call(inputs)
		    return ret[0].Interface()
		},*/
	}

	return html.Must(html.New("*").Funcs(funcMap).Delims("{{%", "%}}").ParseFiles("tpls/" + Name + ".tpl"))
}
Ejemplo n.º 13
0
func getWords(s string) []string {
	// Remove all html tags and such
	plainText := sanitize.HTML(s)

	// Remove all weird characters such as `"^ and so on that are not alphanumeric or spaces
	plainText = nonLetters.ReplaceAllString(plainText, "")

	// Replace all whitespace with 1 regular space
	plainText = whitespace.ReplaceAllString(plainText, " ")

	// Split the plaintext via the single space
	return strings.Split(plainText, " ")
}
Ejemplo n.º 14
0
//MinimalStandard returns a cleaned up standard
func (item XMLLearningStandardItem) MinimalStandard() MinimalStandard {
	standard := MinimalStandard{}

	if len(item.StatementCodes) > 0 {
		standard.Code = item.StatementCodes[0]
	}
	standard.Grades = item.GradeLevels
	if len(item.Statements) > 0 {
		standard.Text = sanitize.HTML(item.Statements[0])
	}

	return standard
}
Ejemplo n.º 15
0
func getCorrection(engine string, queryString string, c chan correctionResult) {
	resp, _ := http.Get(buildUrl(engine, queryString))
	page, _ := ioutil.ReadAll(resp.Body)
	doc, _ := gokogiri.ParseHtml(page)

	suggestedTermResult, err := doc.Root().Search(searchEngines[engine].suggestedTermQuery)
	suggestedTerm := "NULL"
	if err == nil && len(suggestedTermResult) > 0 {
		suggestedTerm = fmt.Sprintf("%v", suggestedTermResult[0])
	} else if err != nil {
		fmt.Println(err)
	}

	topLinkResult, err := doc.Root().Search(searchEngines[engine].topLinkQuery)
	topLink := "NULL"
	if err == nil && len(topLinkResult) > 0 {
		topLink = fmt.Sprintf("%v", topLinkResult[0])
	} else if err != nil {
		fmt.Println(err)
	}

	topTitleResult, err := doc.Root().Search(searchEngines[engine].topTitleQuery)
	topTitle := "NULL"
	if err == nil && len(topTitleResult) > 0 {
		topTitle = fmt.Sprintf("%v", topTitleResult[0])
	} else if err != nil {
		fmt.Println(err)
	}

	doc.Free()
	c <- correctionResult{
		engine:        engine,
		SuggestedTerm: sanitize.HTML(suggestedTerm),
		TopLink:       strings.TrimSpace(sanitize.HTML(topLink)),
		TopTitle:      strings.TrimSpace(sanitize.HTML(topTitle)),
		StatusCode:    resp.StatusCode,
	}
}
Ejemplo n.º 16
0
func GetIdeas() []map[string]interface{} {
	var (
		id        int
		name      string
		email     string
		link      string
		content   string
		timestamp int
	)

	ideas := make([]map[string]interface{}, 0)

	rows, _ := db.Query(`select id, name, email, link, content, strftime("%s", create_time) from idea order by id desc`)
	defer rows.Close()
	for rows.Next() {
		err := rows.Scan(&id, &name, &email, &link, &content, &timestamp)
		if err != nil {
			log.Fatal(err)
		}
		name = sanitize.HTML(name)
		email = sanitize.HTML(email)
		link = sanitize.HTML(link)
		content = sanitize.HTML(content)
		log.Println("Original content: " + content)
		html := string(blackfriday.MarkdownCommon([]byte(content)))
		log.Println("Converted: " + html)
		ideas = append(ideas, map[string]interface{}{
			"id":        id,
			"name":      name,
			"email":     email,
			"link":      link,
			"content":   content,
			"html":      html,
			"timestamp": timestamp,
		})
	}
	return ideas
}
Ejemplo n.º 17
0
// Export method from intermediate schema to solr 4/13 schema.
func (s *Solr4Vufind13v1) Convert(is finc.IntermediateSchema) error {
	s.Allfields = is.Allfields()
	s.Formats = append(s.Formats, is.Format)
	s.Fullrecord = "blob:" + is.RecordID
	s.Fulltext = is.Fulltext
	s.HierarchyParentTitle = append(s.HierarchyParentTitle, is.JournalTitle)
	s.ID = is.RecordID
	s.Imprint = is.Imprint()
	s.ISSN = is.ISSNList()
	s.MegaCollections = append(s.MegaCollections, is.MegaCollection)
	s.PublishDateSort = is.Date.Year()
	s.Publishers = is.Publishers
	s.RecordType = finc.AIRecordType
	s.Series = append(s.Series, is.JournalTitle)
	s.SourceID = is.SourceID
	s.Subtitle = is.ArticleSubtitle
	s.TitleSort = is.SortableTitle()
	s.Topics = is.Subjects
	s.URL = is.URL

	classes := container.NewStringSet()
	for _, s := range is.Subjects {
		for _, class := range SubjectMapping.LookupDefault(s, []string{}) {
			classes.Add(class)
		}
	}
	s.FincClassFacet = classes.Values()

	sanitized := sanitize.HTML(is.ArticleTitle)
	s.Title, s.TitleFull, s.TitleShort = sanitized, sanitized, sanitized

	for _, lang := range is.Languages {
		s.Languages = append(s.Languages, LanguageMap.LookupDefault(lang, lang))
	}

	for _, author := range is.Authors {
		s.SecondaryAuthors = append(s.SecondaryAuthors, author.String())
		s.AuthorFacet = append(s.AuthorFacet, author.String())
	}

	if len(s.SecondaryAuthors) > 0 {
		s.Author = s.SecondaryAuthors[0]
	}

	s.AccessFacet = AIAccessFacet
	s.FormatDe15 = []string{FormatDe15.LookupDefault(is.Format, "")}

	return nil
}
Ejemplo n.º 18
0
// Extract Wesite Content
func Extract(url string) (bookmark *models.Bookmark, err error) {
	c := make(chan string)
	go extractTitle(url, c)
	go extractReadableContent(url, c)

	title, firstParagraph, readableContent := <-c, <-c, <-c

	return &models.Bookmark{
		URL:               url,
		Title:             title,
		FirstParagraph:    firstParagraph,
		ReadableContent:   readableContent,
		SearchableContent: sanitize.HTML(readableContent),
	}, nil
}
Ejemplo n.º 19
0
func getArticleWithSentences(uuid string) *ArticleWithSentences {
	// article := capi.GetArticle(uuid)
	article := content.GetArticle(uuid)

	tidyBody := sanitize.HTML(article.Body)

	sentences := splitTextIntoSentences(tidyBody)
	// for _, s := range *sentences {
	// 	fmt.Println("main: s=", s)
	// }

	aws := ArticleWithSentences{
		article,
		sentences,
	}

	return &aws
}
Ejemplo n.º 20
0
func jeopardyCategory(echoReq *alexa.EchoRequest, session *JeopardySession) (*alexa.EchoResponse, *JeopardySession) {
	msg := ""
	echoResp := alexa.NewEchoResponse()

	// Declare the category
	category, err := echoReq.GetSlotValue("Category")
	_, catExists := JeopardyCategories[category]
	if err != nil || !catExists {
		catNames := []string{}
		for k, _ := range JeopardyCategories {
			catNames = append(catNames, k)
		}

		category = getRandom(catNames)

		msg = msg + getRandom(JeopardyCatSelect) + category + ". "
	} else {
		category = strings.ToLower(category)
	}

	clue, err := getJServiceClue(JeopardyCategories[category])
	if err != nil {
		clue, err = getJServiceClue(JeopardyCategories[category])
		if err != nil {
			echoResp := alexa.NewEchoResponse().OutputSpeech("I'm sorry, but I can't seem to get a question right now.").EndSession(true)
			return echoResp, session
		}
	}

	msg += "From " + category + " for " + strconv.Itoa(clue.Value) + ". " + clue.Question + ". I need your answer in the form of a question."

	session.CurrentQuestion.Category = category
	session.CurrentQuestion.Answer = sanitize.HTML(clue.Answer)
	session.CurrentQuestion.Question = clue.Question
	session.CurrentQuestion.Value = clue.Value

	log.Println(session.CurrentQuestion.Question)
	log.Println(session.CurrentQuestion.Answer)

	echoResp.OutputSpeech(msg).Card("Question", msg).Reprompt("Times up. I need your answer in the form of a question.").EndSession(false)

	return echoResp, session
}
Ejemplo n.º 21
0
// fonction privée
// Permet de retrouver le nombre de réponses pour chaque post
// Permet aussi de réduire la description du texte de desc à 250 caractères
func (pf PageForumList) injectDataToDisplay(forums []Forum) []Forum {

	lenForum := len(forums)

	for i := 0; i < lenForum; i++ {
		id := forums[i].Id
		// permet de réaliser des extraits si le texte est trop long
		extrait := sanitize.HTML(forums[i].Text)
		if len(extrait) > 250 {
			extrait = extrait[0:250]
		}
		forums[i].Text = "<p>" + extrait + "</p>"
		// permet de compter ne nombres de réponses
		forums[i].PostNumb = forums[i].CountPost(id)
		// permet de créer une url du lien
		forums[i].Url = "/forum/post/" + Itoa(int(forums[i].Id))
	}
	return forums
}
Ejemplo n.º 22
0
// fonction privée
// Permet de retrouver le nombre de réponses pour chaque post
// Permet aussi de réduire la description du texte de desc à 250 caractères
func (pt PageTutorialList) injectDataToDisplay(tutorials []Tutorial) []Tutorial {

	lenTuto := len(tutorials)

	for i := 0; i < lenTuto; i++ {
		id := tutorials[i].Id
		// permet de réaliser des extraits si le texte est trop long
		extrait := sanitize.HTML(tutorials[i].Text)
		if len(extrait) > 250 {
			extrait = extrait[0:250]
		}
		tutorials[i].Text = "<p>" + extrait + "</p>"
		// permet de compter ne nombres de réponses
		tutorials[i].PostNumb = tutorials[i].CountPost(id)
		// permet de créer une url du lien
		tutorials[i].CategoryTitle = tutorials[i].GetCatTitle()
	}
	return tutorials
}
Ejemplo n.º 23
0
func clean(s string) string {
	s = sanitize.HTML(s)
	s = strings.Trim(s, " ")
	const ellipsis = "\u2026"
	if len(s) > characterCount {
		i := characterCount - 1
		c := string(s[i])
		for c != " " {
			i--
			c = string(s[i])
		}
		switch string(s[i-1]) {
		case ".", ",":
			return s[:i-1] + ellipsis
		default:
			return s[:i] + ellipsis
		}
	}
	return s
}
Ejemplo n.º 24
0
func Import(db *sql.DB, xmlReader io.Reader) error {
	parsed := &disqus{}
	decoder := xml.NewDecoder(xmlReader)
	if err := decoder.Decode(parsed); err != nil {
		return err
	}
	comments := make([]models.Comment, 0)
	for _, post := range parsed.Posts {
		thread, err := parsed.findThread(post.Thread.Id)
		if err != nil {
			fmt.Println("Could not find thread reference", post.Thread.Id)
		}
		if post.IsDeleted == "true" {
			continue
		}
		createdAt, err := time.Parse(time.RFC3339, post.CreatedAt)
		if err != nil {
			createdAt = time.Now()
		}
		body := sanitize.HTML(post.Message)
		comment := models.NewComment(post.Author.Email, post.Author.Name, "", body, thread.Link, post.IpAddress)
		comment.Created = createdAt.Unix()
		comment.Approved = post.IsSpam == "false"
		comments = append(comments, comment)
	}

	total := len(parsed.Posts)
	fmt.Println("Read", total, "from the file.")

	for i, comment := range comments {
		if err := comment.Save(db); err != nil {
			total--
			fmt.Println("Could not import comment", i)
			fmt.Println(err)
		}
	}

	fmt.Println("Wrote", total, "comments to the database.")

	return nil
}
Ejemplo n.º 25
0
func commandDeployStatus(message models.Message, publishMsgs chan<- models.Message, connector models.Connector) {
	tokens := strings.Split(message.In.Text, " ")
	d := bambooapi.DeployResults(connector.Server, connector.Login, connector.Pass)
	for _, de := range d {
		for _, e := range de.Environmentstatuses {
			detail := e.Deploymentresult.Deploymentversion.Name + " to " + e.Environment.Name
			if strings.Contains(strings.ToLower(detail), strings.ToLower(tokens[2])) {
				message.In.Tags = parse.TagAppend(message.In.Tags, connector.Tags)
				message.Out.Text = "Bamboo Deploy " + detail + " " + e.Deploymentresult.Deploymentstate
				message.Out.Detail = html.UnescapeString(sanitize.HTML(e.Deploymentresult.Reasonsummary))
				message.Out.Link = "https://" + connector.Server + "/builds/deploy/viewDeploymentResult.action?deploymentResultId=" + strconv.Itoa(e.Deploymentresult.ID)
				if e.Deploymentresult.Deploymentstate == "SUCCESS" {
					message.Out.Status = "SUCCESS"
				} else {
					message.Out.Status = "FAIL"
				}
				publishMsgs <- message
			}
		}
	}
}
Ejemplo n.º 26
0
// Send will store message to database and send to messaging server
// Send also inserting new email to default channel if not defined
func send(c *gin.Context) {
	var msg Message

	// Binding request to message struct
	// If passed data not complete, then show error response
	err := c.BindJSON(&msg)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"message": errValidationIncomplete.Error(),
			"errors":  []string{err.Error()},
		})
		return
	}

	// If text message not set,
	// Sanitize from message HTML into text
	if len(msg.Text) <= 0 {
		msg.Text = sanitize.HTML(msg.HTML)
	}

	// Save to database
	msg.Status = 0
	msg.Delay = 0

	log.Println(cfg.UString("database.name", "pes"))
	log.Println(cfg.UString("collection.message", "message"))

	err = sess.DB(cfg.UString("database.name", "pes")).C(cfg.UString("collection.message", "message")).Insert(msg)
	if err != nil {
		log.Printf("Error inserting message to database: %v with error %v", msg, err)
	}

	// Sending to messaging server

	c.JSON(http.StatusOK, gin.H{
		"message": "Success to queue",
		"errors":  []string{},
	})

}
Ejemplo n.º 27
0
func GetResult(server string, user string, pass string, key string) (result Result) {
	url := "https://" + user + ":" + pass + "@" + server
	url += "/builds/rest/api/latest/result/" + key
	req, err := http.NewRequest("GET", url, bytes.NewBufferString(""))
	if err != nil {
		log.Println(err)
	}
	client := &http.Client{}
	res, err := client.Do(req)
	if err != nil {
		log.Println(err)
	}
	defer res.Body.Close()
	body, err := ioutil.ReadAll(res.Body)
	if err != nil {
		log.Println(err)
	}
	xml.Unmarshal(body, &result)
	result.Plan = result.PlanData.Name
	result.Responsible = sanitize.HTML(result.Responsible)
	return result
}
Ejemplo n.º 28
0
// Write the body of the email to the specified writer.
func (e *Email) writeBody(w *multipart.Writer) error {
	var (
		buff      = &bytes.Buffer{}
		altWriter = multipart.NewWriter(buff)
	)
	p, err := w.CreatePart(textproto.MIMEHeader{
		"Content-Type": []string{
			fmt.Sprintf("multipart/alternative; boundary=%s", altWriter.Boundary()),
		},
	})
	if err != nil {
		return err
	}
	if e.Text == "" {
		e.Text = sanitize.HTML(e.Html)
	}
	if e.Html == "" {
		e.Html = toHTML(e.Text)
	}
	if err := (Attachment{
		ContentType: "text/plain; charset=utf-8",
		Content:     e.Text,
	}.Write(altWriter)); err != nil {
		return err
	}
	if err := (Attachment{
		ContentType: "text/html; charset=utf-8",
		Content:     e.Html,
	}.Write(altWriter)); err != nil {
		return err
	}
	if err := altWriter.Close(); err != nil {
		return err
	}
	if _, err := io.Copy(p, buff); err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 29
0
func main() {
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush() // Don't forget to flush at the end.

	re := regexp.MustCompile(`\(([^()]*)\)`)

	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		t := scanner.Text() // Read line.

		// XML from theyworkforyou.com are not valid.
		// Unescape some weird characters.
		t = html.UnescapeString(t)

		if strings.Contains(t, "<p ") {
			// In paragraphs, remove all trace of HTML.
			t = sanitize.HTML(t)

			// Re-escape a few characters which shouldn't
			// be escpaed in an XML file.
			t = html.EscapeString(t)

			// Remove parentheses.
			t = re.ReplaceAllString(t, "$1")

			// Trim spaces, re-add <p> tags and output the line.
			fmt.Fprintf(w, "<p>%s</p>\n", strings.TrimSpace(t))

			continue // Continue to next element
		}

		// Not a pragraph. Output the line.
		fmt.Fprintf(w, "%s\n", t)
	}
	if err := scanner.Err(); err != nil {
		fmt.Fprintln(os.Stderr, "reading standard input:", err)
	}
}
Ejemplo n.º 30
0
func fefe(i *data.Item, sourceURL string, doc *goquery.Document) {
	if !strings.Contains(sourceURL, "blog.fefe.de/?ts") {
		return
	}
	fmt.Println("Running Fefes Blog plugin.")

	selection := doc.Find("li")

	if len(selection.Nodes) == 0 {
		fmt.Println("Fefes Blog plugin found no li. " + sourceURL)
		return
	}

	if len(selection.Nodes) > 1 {
		fmt.Println("Fefes Blog plugin found >1 li. " + sourceURL)
	}

	buf := new(bytes.Buffer)
	err := html.Render(buf, selection.Nodes[0])
	if err != nil {
		fmt.Println("Fefes Blog plugin error while rendering. " + sourceURL + "- " + err.Error())
		return
	}
	i.Description = buf.String()
	start := strings.Index(i.Description, "</a>") + 4
	end := strings.Index(i.Description, "</li>")
	i.Description = i.Description[start:end]

	words := strings.Fields(sanitize.HTML(i.Description))
	i.Caption = ""
	for a := 0; len(i.Caption) < 20 && a < len(words); a++ {
		i.Caption += words[a] + " "
	}
	i.Caption = "Fefes Blog - " + strings.TrimSpace(i.Caption) + "..."
	i.ImageURL = ""
}