<commit_before>package refugeemaps

import (
	"appengine"
	"html/template"
	"net/http"

	"github.com/gorilla/mux"

	"lib/categories"
	"lib/city"
	"lib/constants"
	"lib/hotspots"
)

var (
	router    = mux.NewRouter()
	templates = template.Must(template.ParseGlob("templates/*"))
)

// Initialize
func init() {
	router.HandleFunc("/", RootHandler)
	router.HandleFunc("/_api/hotspots/{cityId}.json", HotspotsJSONHandler)
	router.NotFoundHandler = http.HandlerFunc(NotFoundHandler)

	http.Handle("/", router)
}

// RootHandler handles the main call.
func RootHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	selectedCity := city.Get(r)
	allCategories := categories.Load(c)

	templateExecuteError := templates.ExecuteTemplate(w, "indexPage", map[string]interface{}{
		"title":      constants.SiteName,
		"siteName":   constants.SiteName,
		"categories": allCategories,
		"city":       selectedCity,
	})
	if templateExecuteError != nil {
		c.Errorf("main.RootHandler template: %v", templateExecuteError)
		return
	}
}

// HotspotsJSONHandler returns hotspots
func HotspotsJSONHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	vars := mux.Vars(r)
	selectedCity, exists := city.GetById(r, vars["cityId"])
	if !exists {
		NotFoundHandler(w, r)
		return
	}

	selectedCity.SpreadsheetId = "15Na8ihDIljcRatsPkNQFA1rQLM6C08AC0VJVyGFKioI"

	w.Header().Set("Content-Type", "application/json")
	w.Write(hotspots.GetAsJSON(c, selectedCity))
}

// NotFoundHandler handles 404
func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	w.WriteHeader(404)<commit_msg>feat(server): use real city mapping sheet<commit_after>package refugeemaps

import (
	"appengine"
	"html/template"
	"net/http"

	"github.com/gorilla/mux"

	"lib/categories"
	"lib/city"
	"lib/constants"
	"lib/hotspots"
)

var (
	router    = mux.NewRouter()
	templates = template.Must(template.ParseGlob("templates/*"))
)

// Initialize
func init() {
	router.HandleFunc("/", RootHandler)
	router.HandleFunc("/_api/hotspots/{cityId}.json", HotspotsJSONHandler)
	router.NotFoundHandler = http.HandlerFunc(NotFoundHandler)

	http.Handle("/", router)
}

// RootHandler handles the main call.
func RootHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	selectedCity := city.Get(r)
	allCategories := categories.Load(c)

	templateExecuteError := templates.ExecuteTemplate(w, "indexPage", map[string]interface{}{
		"title":      constants.SiteName,
		"siteName":   constants.SiteName,
		"categories": allCategories,
		"city":       selectedCity,
	})
	if templateExecuteError != nil {
		c.Errorf("main.RootHandler template: %v", templateExecuteError)
		return
	}
}

// HotspotsJSONHandler returns hotspots
func HotspotsJSONHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	vars := mux.Vars(r)
	selectedCity, exists := city.GetById(r, vars["cityId"])
	if !exists {
		NotFoundHandler(w, r)
		return
	}

	w.Header().Set("Content-Type", "application/json")
	w.Write(hotspots.GetAsJSON(c, selectedCity))
}

// NotFoundHandler handles 404
func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	w.WriteHeader(404)
{'fraction_non_alphanumeric': 0.14386937769562538, 'fraction_numerical': 0.0061614294516327784, 'mean_word_length': 5.012962962962963, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '5534742', 'n_tokens_mistral': 1163, 'n_tokens_neox': 1106, 'n_words': 204}