Create a 'Follow' type
This commit is contained in:
parent
80f6787aa0
commit
2210b61b3c
23
persistence/follows.go
Normal file
23
persistence/follows.go
Normal file
@ -0,0 +1,23 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"offline_twitter/scraper"
|
||||
)
|
||||
|
||||
|
||||
/**
|
||||
* Create a Type for this to make it easier to expand later
|
||||
*/
|
||||
type Follow struct {
|
||||
Handle scraper.UserHandle `yaml:"user"`
|
||||
AutoFetch bool `yaml:"auto_fetch_tweets"`
|
||||
}
|
||||
|
||||
func (p Profile) IsFollowing(handle scraper.UserHandle) bool {
|
||||
for _, follow := range p.UsersList {
|
||||
if follow.Handle == handle {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
23
persistence/follows_test.go
Normal file
23
persistence/follows_test.go
Normal file
@ -0,0 +1,23 @@
|
||||
package persistence_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "offline_twitter/persistence"
|
||||
)
|
||||
|
||||
|
||||
func TestIsFollowing(t *testing.T) {
|
||||
p := Profile{}
|
||||
p.UsersList = []Follow{
|
||||
Follow{Handle: "guy1"},
|
||||
Follow{Handle: "guy2"},
|
||||
}
|
||||
|
||||
if p.IsFollowing("guy3") {
|
||||
t.Errorf("Should not be following guy3")
|
||||
}
|
||||
if !p.IsFollowing("guy2") {
|
||||
t.Errorf("Should be following guy2")
|
||||
}
|
||||
}
|
@ -46,6 +46,7 @@ func (d DefaultDownloader) Curl(url string, outpath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Downloads an Image, and if successful, marks it as downloaded in the DB
|
||||
*/
|
||||
@ -146,11 +147,8 @@ func (p Profile) DownloadUserContentFor(u *scraper.User) error {
|
||||
* Enable injecting a custom MediaDownloader (i.e., for testing)
|
||||
*/
|
||||
func (p Profile) DownloadUserContentWithInjector(u *scraper.User, downloader MediaDownloader) error {
|
||||
var err error
|
||||
var outfile string
|
||||
|
||||
outfile = path.Join(p.ProfileDir, "profile_images", u.ProfileImageLocalPath)
|
||||
err = downloader.Curl(u.ProfileImageUrl, outfile)
|
||||
outfile := path.Join(p.ProfileDir, "profile_images", u.ProfileImageLocalPath)
|
||||
err := downloader.Curl(u.ProfileImageUrl, outfile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -8,8 +8,6 @@ import (
|
||||
"database/sql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"offline_twitter/scraper"
|
||||
)
|
||||
|
||||
//go:embed schema.sql
|
||||
@ -17,16 +15,9 @@ var sql_init string
|
||||
|
||||
type Settings struct {}
|
||||
|
||||
/**
|
||||
* Create a Type for this to make it easier to expand later
|
||||
*/
|
||||
type UsersList []struct {
|
||||
Handle scraper.UserHandle `yaml:"user"`
|
||||
}
|
||||
|
||||
type Profile struct {
|
||||
ProfileDir string
|
||||
UsersList UsersList
|
||||
UsersList []Follow
|
||||
Settings Settings
|
||||
DB *sql.DB
|
||||
}
|
||||
@ -139,7 +130,7 @@ func NewProfile(target_dir string) (Profile, error) {
|
||||
return Profile{}, err
|
||||
}
|
||||
|
||||
return Profile{target_dir, UsersList{}, settings, db}, nil
|
||||
return Profile{target_dir, []Follow{}, settings, db}, nil
|
||||
}
|
||||
|
||||
|
||||
@ -171,7 +162,7 @@ func LoadProfile(profile_dir string) (Profile, error) {
|
||||
if err != nil {
|
||||
return Profile{}, err
|
||||
}
|
||||
users_list := UsersList{}
|
||||
users_list := []Follow{}
|
||||
err = yaml.Unmarshal(users_data, &users_list);
|
||||
if err != nil {
|
||||
return Profile{}, err
|
||||
|
Loading…
x
Reference in New Issue
Block a user