<commit_before>/* Copyright (c) 2015, <NAME> <<EMAIL>> */
/* See LICENSE for licensing information */

package main

import (
	"archive/zip"
	"bytes"
	"encoding/xml"
	"flag"
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"sort"
	"strings"
)

// Repo is an F-Droid repository holding apps and apks
type Repo struct {
	Apps []App `xml:"application"`
}

type CommaList []string

func (cl *CommaList) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	var content string
	if err := d.DecodeElement(&content, &start); err != nil {
		return err
	}
	*cl = strings.Split(content, ",")
	return nil
}

// App is an Android application
type App struct {
	ID      string    `xml:"id"`
	Name    string    `xml:"name"`
	Summary string    `xml:"summary"`
	Desc    string    `xml:"desc"`
	License string    `xml:"license"`
	Categs  CommaList `xml:"categories"`
	CVName  string    `xml:"marketversion"`
	CVCode  uint      `xml:"marketvercode"`
	Website string    `xml:"web"`
	Source  string    `xml:"source"`
	Tracker string    `xml:"tracker"`
	Apks    []Apk     `xml:"package"`
	CurApk  *Apk
}

// Apk is an Android package
type Apk struct {
	VName  string    `xml:"version"`
	VCode  uint      `xml:"versioncode"`
	Size   int       `xml:"size"`
	MinSdk int       `xml:"sdkver"`
	MaxSdk int       `xml:"maxsdkver"`
	ABIs   CommaList `xml:"nativecode"`
}

func (app *App) prepareData() {
	for _, apk := range app.Apks {
		app.CurApk = &apk
		if app.CVCode >= apk.VCode {
			break
		}
	}
}

func (app *App) writeShort(w io.Writer) {
	fmt.Fprintf(w, "%s | %s %s\n", app.ID, app.Name, app.CurApk.VName)
	fmt.Fprintf(w, "    %s\n", app.Summary)
}

func (app *App) writeDetailed(w io.Writer) {
	p := func(title string, format string, args ...interface{}) {
		if format == "" {
			fmt.Fprintln(w, title)
		} else {
			fmt.Fprintf(w, "%s %s\n", title, fmt.Sprintf(format, args...))
		}
	}
	p("Name             :", "%s", app.Name)
	p("Summary          :", "%s", app.Summary)
	p("Current Version  :", "%s (%d)", app.CurApk.VName, app.CurApk.VCode)
	p("Upstream Version :", "%s (%d)", app.CVName, app.CVCode)
	p("License          :", "%s", app.License)
	if app.Categs != nil {
		p("Categories       :", "%s", strings.Join(app.Categs, ", "))
	}
	if app.Website != "" {
		p("Website          :", "%s", app.Website)
	}
	if app.Source != "" {
		p("Source           :", "%s", app.Source)
	}
	if app.Tracker != "" {
		p("Tracker          :", "%s", app.Tracker)
	}
	// p("Description     :", "%s", app.Desc) // TODO: parse html, 80 column wrapping
	fmt.Println()
	p("Available Versions :", "")
	for _, apk := range app.Apks {
		fmt.Println()
		p("    Name   :", "%s (%d)", apk.VName, apk.VCode)
		p("    Size   :", "%d", apk.Size)
		p("    MinSdk :", "%d", apk.MinSdk)
		if apk.MaxSdk > 0 {
			p("    MaxSdk :", "%d", apk.MaxSdk)
		}
		if apk.ABIs != nil {
			p("    ABIs   :", "%s", strings.Join(apk.ABIs, ", "))
		}
	}
}

const indexName = "index.jar"<commit_msg>Add support for donation methods<commit_after>/* Copyright (c) 2015, <NAME> <<EMAIL>> */
/* See LICENSE for licensing information */

package main

import (
	"archive/zip"
	"bytes"
	"encoding/xml"
	"flag"
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"sort"
	"strings"
)

// Repo is an F-Droid repository holding apps and apks
type Repo struct {
	Apps []App `xml:"application"`
}

type CommaList []string

func (cl *CommaList) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
	var content string
	if err := d.DecodeElement(&content, &start); err != nil {
		return err
	}
	*cl = strings.Split(content, ",")
	return nil
}

// App is an Android application
type App struct {
	ID      string    `xml:"id"`
	Name    string    `xml:"name"`
	Summary string    `xml:"summary"`
	Desc    string    `xml:"desc"`
	License string    `xml:"license"`
	Categs  CommaList `xml:"categories"`

	Website  string `xml:"web"`
	Source   string `xml:"source"`
	Tracker  string `xml:"tracker"`
	Donate   string `xml:"donate"`
	Bitcoin  string `xml:"bitcoin"`
	Litecoin string `xml:"litecoin"`
	Dogecoin string `xml:"dogecoin"`
	FlattrID string `xml:"flattr"`

	Apks []Apk `xml:"package"`

	CVName string `xml:"marketversion"`
	CVCode uint   `xml:"marketvercode"`
	CurApk *Apk
}

// Apk is an Android package
type Apk struct {
	VName  string    `xml:"version"`
	VCode  uint      `xml:"versioncode"`
	Size   int       `xml:"size"`
	MinSdk int       `xml:"sdkver"`
	MaxSdk int       `xml:"maxsdkver"`
	ABIs   CommaList `xml:"nativecode"`
}

func (app *App) prepareData() {
	for _, apk := range app.Apks {
		app.CurApk = &apk
		if app.CVCode >= apk.VCode {
			break
		}
	}
}

func (app *App) writeShort(w io.Writer) {
	fmt.Fprintf(w, "%s | %s %s\n", app.ID, app.Name, app.CurApk.VName)
	fmt.Fprintf(w, "    %s\n", app.Summary)
}

func (app *App) writeDetailed(w io.Writer) {
	p := func(title string, format string, args ...interface{}) {
		if format == "" {
			fmt.Fprintln(w, title)
		} else {
			fmt.Fprintf(w, "%s %s\n", title, fmt.Sprintf(format, args...))
		}
	}
	p("Name             :", "%s", app.Name)
	p("Summary          :", "%s", app.Summary)
	p("Current Version  :", "%s (%d)", app.CurApk.VName, app.CurApk.VCode)
	p("Upstream Version :", "%s (%d)", app.CVName, app.CVCode)
	p("License          :", "%s", app.License)
	if app.Categs != nil {
		p("Categories       :", "%s", strings.Join(app.Categs, ", "))
	}
	if app.Website != "" {
		p("Website          :", "%s", app.Website)
	}
	if app.Source != "" {
		p("Source           :", "%s", app.Source)
	}
	if app.Tracker != "" {
		p("Tracker          :", "%s", app.Tracker)
	}
	if app.Donate != "" {
		p("Donate           :", "%s", app.Donate)
	}
	if app.Bitcoin != "" {
		p("Bitcoin          :", "bitcoin:%s", app.Bitcoin)
	}
	if app.Litecoin != "" {
		p("Litecoin         :", "litecoin:%s", app.Litecoin)
	}
	if app.Dogecoin != "" {
		p("Dogecoin         :", "dogecoin:%s", app.Dogecoin)
	}
	if app.FlattrID != "" {
		p("Flattr           :", "https://flattr.com/thing/%s", app.FlattrID)
	}
	// p("Description     :", "%s", app.Desc) // TODO: parse html, 80 column wrapping
	fmt.Println()
	p("Available Versions :", "")
	for _, apk := range app.Apks {
		fmt.Println()
		p("    Name   :", "%s (%d)", apk.VName, apk.VCode)
		p("    Size   :", "%d", apk.Size)
		p("    MinSdk :", "%d", apk.MinSdk)
		if apk.MaxSdk > 0 {
			p("    MaxSdk :", "%d", apk.MaxSdk)
		}
		if apk.ABIs != nil {
			p("    ABIs   :", "%s", strings.Join(apk.ABIs, ", "))
		}
	}
}

const indexName = "index.jar"
{'fraction_non_alphanumeric': 0.1945392491467577, 'fraction_numerical': 0.0021718895439031957, 'mean_word_length': 2.895468277945619, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 49}, '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': '854190', 'n_tokens_mistral': 2623, 'n_tokens_neox': 2492, 'n_words': 603}