app

package
v0.0.0-...-37d9800 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2016 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Reddit audiences crawler Rémy Mathieu © 2016

Reddit audiences crawler Rémy Mathieu © 2016

Reddit audiences crawler Rémy Mathieu © 2016

Index

Constants

View Source
const (
	REDDIT_SUBREDDIT_URL           = "https://www.reddit.com/r/"
	MIN_SECONDS_BETWEEN_EACH_CRAWL = 1
)
View Source
const (
	SESSION_EXPIRATION = "60m"
)

Variables

This section is empty.

Functions

func Average

func Average(audiences []db.Audience) int64

Average computes the average in the given audiences. Very basic algorithm.

func Capitalize

func Capitalize(str string) string

Capitalize capitalizes the given string.

func ComputeArticleState

func ComputeArticleState(article db.Article, ranking []db.Ranking) db.ArticleState

func CreateSession

func CreateSession(conn db.Conn, user db.User, creationTime time.Time) (db.Session, error)

CreationSessions creates in-base a session for the given user already created in database.

func CryptPassword

func CryptPassword(password string) (string, error)

func Feeder

func Feeder(a *App)

Feeder retrieves the audience of subreddits for which the last crawl time is more than some minutes.

func GetUser

func GetUser(conn db.Conn, r *http.Request) db.User

func IsPasswordSecure

func IsPasswordSecure(password string) bool

IsPasswordSecure checks that the given password is strong enough to be used.

func LowestHighest

func LowestHighest(audiences []db.Audience) (db.Audience, db.Audience)

LowestHighest is a quick implementation retrieving the lowest and the highest audience for the given slice of audiences.

func NewRequest

func NewRequest(url string) (*http.Request, error)

func ReadTemplates

func ReadTemplates(app *App) (*template.Template, error)

ReadTemplates looks and reads in the configured directory for all available templates.

func SetSessionCookie

func SetSessionCookie(w http.ResponseWriter, session db.Session)

func StartCleanSessionsJob

func StartCleanSessionsJob(a *App)

func StartCrawlingJob

func StartCrawlingJob(a *App)

func TemplateHelpers

func TemplateHelpers() template.FuncMap

func Worker

func Worker(a *App)

Worker is the routine dealing with the HTTP call + reading hte DOM.

Types

type App

type App struct {
	Templates *template.Template
	Config    Config
	// contains filtered or unexported fields
}

func (*App) Add

func (a *App) Add(pattern string, handler http.Handler, methods ...string)

func (*App) AddApi

func (a *App) AddApi(pattern string, handler http.Handler, methods ...string)

func (*App) DB

func (a *App) DB() db.Conn

DB opens a connection to PostgreSQL.

func (*App) Init

func (a *App) Init()

func (*App) Listen

func (a *App) Listen() error

func (*App) StartJobs

func (a *App) StartJobs()

type Config

type Config struct {
	DB           string `envconfig:"DB,default=host=/var/run/postgresql sslmode=disable user=audiences dbname=audiences password=audiences"`
	PublicDir    string `envconfig:"DIR,default=static/"`
	Crawl        bool   `envconfig:"optional,default=true,CRAWL"`
	TemplatesDir string `envconfig:"TEMPLATES,default=templates/"`
	ListenAddr   string `envconfig:"ADDR,default=:9000"`
}

type Params

type Params struct {
	// Name of the current page, not always set
	Page string
	// LoggedIn is set to true when the current user
	// is logged in.
	LoggedIn bool
	User     ParamsUser
}

func TmplParams

func TmplParams(app *App, r *http.Request, page string) Params

type ParamsUser

type ParamsUser struct {
	Email     string
	Firstname string
	Lastname  string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL