Implementing configuration

Very tired. Must sleep. Wanted to work. Working on making config.json a thing so rss feed can be edited outside of the code.
This commit is contained in:
gmemstr 2017-07-01 00:26:32 -07:00
parent baa3ef76ae
commit a78472364c
4 changed files with 60 additions and 38 deletions

7
config.json Normal file
View file

@ -0,0 +1,7 @@
{
"Name": "Git Galaxy Stargazers",
"Host": "Gabriel Simmer",
"Email": "gabriel@gitgalaxy.com",
"Image": "https://podcast.gitgalaxy.com/assets/podcast_image.png",
"PodcastUrl": "https://podcast.gitgalaxy.com"
}

View file

@ -1,21 +1,16 @@
{ {
"version": "https://jsonfeed.org/version/1", "version": "https://jsonfeed.org/version/1",
"title": "Git Galaxy Stargazers", "title": "",
"home_page_url": "https://gitgalaxy.com",
"description": "discussion about open source projects", "description": "discussion about open source projects",
"author": { "author": {},
"name": "Gabriel Simmer"
},
"items": [ "items": [
{ {
"id": "", "id": "",
"url": "https://podcast.gitgalaxy.com/download/2017-07-12_TESTING WORLD.mp3", "url": "/download/2017-07-12_TESTING WORLD.mp3",
"title": "TESTING WORLD", "title": "TESTING WORLD",
"summary": "Hello, World!", "summary": "testing4",
"date_published": "2017-07-12T00:00:00Z", "date_published": "2017-07-12T00:00:00Z",
"author": { "author": {}
"name": "Gabriel Simmer"
}
} }
] ]
} }

View file

@ -1,20 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"> <?xml version="1.0" encoding="UTF-8"?><rss version="2.0">
<channel> <channel>
<title>Git Galaxy Stargazers</title> <title></title>
<link>https://gitgalaxy.com</link> <link></link>
<description>discussion about open source projects</description> <description>discussion about open source projects</description>
<managingEditor>gabriel@gitgalaxy.com (Gabriel Simmer)</managingEditor> <pubDate>Sat, 01 Jul 2017 00:23:10 -0700</pubDate>
<pubDate>Mon, 19 Jun 2017 07:36:34 -0700</pubDate>
<image> <image>
<url>https://podcast.gitgalaxy.com/assets/podcast_image.png</url> <url></url>
<title></title> <title></title>
<link></link> <link></link>
</image> </image>
<item> <item>
<title>TESTING WORLD</title> <title>TESTING WORLD</title>
<link>https://podcast.gitgalaxy.com/download/2017-07-12_TESTING WORLD.mp3</link> <link>/download/2017-07-12_TESTING WORLD.mp3</link>
<description>Hello, World!</description> <description>testing4</description>
<enclosure url="https://podcast.gitgalaxy.com/download/2017-07-12_TESTING WORLD.mp3" length="100" type="audio/mpeg"></enclosure> <enclosure url="/download/2017-07-12_TESTING WORLD.mp3" length="100" type="audio/mpeg"></enclosure>
<pubDate>Wed, 12 Jul 2017 00:00:00 +0000</pubDate> <pubDate>Wed, 12 Jul 2017 00:00:00 +0000</pubDate>
</item> </item>
</channel> </channel>

View file

@ -9,8 +9,17 @@ import (
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/gmemstr/feeds" "github.com/gmemstr/feeds"
"github.com/Tkanos/gonfig"
) )
type Configuration struct {
Name string
Host string
Email string
Image string
PodcastUrl string
}
func watch() { func watch() {
watcher, err := fsnotify.NewWatcher() watcher, err := fsnotify.NewWatcher()
if err != nil { if err != nil {
@ -42,6 +51,12 @@ func watch() {
} }
func generate_rss() { func generate_rss() {
configuration := Configuration{}
err := gonfig.GetConf("config.json", &configuration)
if err != nil {
log.Fatal(err)
}
fmt.Println(configuration)
now := time.Now() now := time.Now()
files, err := ioutil.ReadDir("podcasts") files, err := ioutil.ReadDir("podcasts")
if err != nil { if err != nil {
@ -49,18 +64,23 @@ func generate_rss() {
} }
feed := &feeds.Feed{ feed := &feeds.Feed{
Title: "Git Galaxy Stargazers", Title: configuration.Name,
Link: &feeds.Link{Href: "https://gitgalaxy.com"}, Link: &feeds.Link{Href: configuration.PodcastUrl},
Description: "discussion about open source projects", Description: "discussion about open source projects",
Author: &feeds.Author{Name: "Gabriel Simmer", Email: "gabriel@gitgalaxy.com"}, Author: &feeds.Author{Name: configuration.Host, Email: configuration.Email},
Created: now, Created: now,
Image: &feeds.Image{Url: "https://podcast.gitgalaxy.com/assets/podcast_image.png"}, Image: &feeds.Image{Url: configuration.Image},
} }
for _, file := range files { for _, file := range files {
if strings.Contains(file.Name(), ".mp3") {
s := strings.Split(file.Name(), "_") s := strings.Split(file.Name(), "_")
t := strings.Split(s[1], ".") t := strings.Split(s[1], ".")
title := t[0] title := t[0]
description,err := ioutil.ReadFile("podcasts/" + strings.Replace(file.Name(), ".mp3", "_SHOWNOTES.md", 2))
if err != nil {
log.Fatal(err)
}
date, err := time.Parse("2006-01-02", s[0]) date, err := time.Parse("2006-01-02", s[0])
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -68,14 +88,15 @@ func generate_rss() {
feed.Items = []*feeds.Item{ feed.Items = []*feeds.Item{
&feeds.Item{ &feeds.Item{
Title: title, Title: title,
Link: &feeds.Link{Href: "https://podcast.gitgalaxy.com/download/" + file.Name(), Length: "100", Type: "audio/mpeg"}, Link: &feeds.Link{Href: configuration.PodcastUrl + "/download/" + file.Name(), Length: "100", Type: "audio/mpeg"},
Enclosure: &feeds.Enclosure{Url: "https://podcast.gitgalaxy.com/download/" + file.Name(), Length: "100", Type: "audio/mpeg"}, Enclosure: &feeds.Enclosure{Url: configuration.PodcastUrl + "/download/" + file.Name(), Length: "100", Type: "audio/mpeg"},
Description: "Hello, World!", Description: string(description),
Author: &feeds.Author{Name: "Gabriel Simmer", Email: "gabriel@gitgalaxy.com"}, Author: &feeds.Author{Name: configuration.Host, Email: configuration.Email},
Created: date, Created: date,
}, },
} }
} }
}
rss, err := feed.ToRss() rss, err := feed.ToRss()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)