Skip to content

Commit

Permalink
Merge branch 'gh-pages' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
shervinafshar committed May 18, 2021
2 parents 3519c6b + 6077ba9 commit c2c1061
Show file tree
Hide file tree
Showing 32 changed files with 5,537 additions and 59 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ flags were resolved for the initial import:
- The script `regions.py` lists all regions and some selected sub-regions with their metadata.
- The script `regions-wp.py` shows the Wikipedia URL for the flag page.
- The script `missing.sh` shows all such regions that we don't have flags for.
- The script `make-aliases.sh` makes symlinks for regions that use flag of another
region.
- The script `download-wp.py` downloads missing flags from Wikipedia and generating
optimized SVG and PNG versions.
- The script `make-aliases.sh` makes symlinks for regions that use flag of another region.
- The script `download-wp.sh` downloads missing flags from Wikipedia and optionally you can generate optimized SVG and PNG versions (e.g., download-wp.py true).
- The script `update.sh` automatically regenerates all files and outputs optimized png.
- The script `convert.sh` converts SVG to PNG with ability to specify Width or Height.

You can use the [waveflag script from the Noto fonts project](https://code.google.com/p/noto/source/browse/color_emoji/waveflag.c)
to _wave_ PNG flags.
Expand All @@ -80,7 +80,8 @@ national laws), make a note of it in file `COPYING`.
To download missing flags, run `download-wp.py`.

To update to latest flags from Wikipedia, delete the `html`, `svg`, and `png`
directories, then run `make-aliases.sh` followed by `download-wp.py`.
directories, then run `make-aliases.sh` followed by `download-wp.py` or you can use `update.sh`.



# License
Expand Down
8 changes: 8 additions & 0 deletions SOURCES
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ AR https://commons.wikimedia.org/wiki/File:Flag_of_Argentina.svg
AS https://commons.wikimedia.org/wiki/File:Flag_of_American_Samoa.svg
AT https://commons.wikimedia.org/wiki/File:Flag_of_Austria.svg
AU https://commons.wikimedia.org/wiki/File:Flag_of_Australia.svg
AU-ACT https://commons.wikimedia.org/wiki/File:Flag_of_the_Australian_Capital_Territory.svg
AU-NSW https://commons.wikimedia.org/wiki/File:Flag_of_New_South_Wales.svg
AU-NT https://commons.wikimedia.org/wiki/File:Flag_of_the_Northern_Territory.svg
AU-QLD https://commons.wikimedia.org/wiki/File:Flag_of_Queensland.svg
AU-SA https://commons.wikimedia.org/wiki/File:Flag_of_South_Australia.svg
AU-TAS https://commons.wikimedia.org/wiki/File:Flag_of_Tasmania.svg
AU-VIC https://commons.wikimedia.org/wiki/File:Flag_of_Victoria_(Australia).svg
AU-WA https://commons.wikimedia.org/wiki/File:Flag_of_Western_Australia.svg
AW https://commons.wikimedia.org/wiki/File:Flag_of_Aruba.svg
AX https://commons.wikimedia.org/wiki/File:Flag_of_Åland.svg
AZ https://commons.wikimedia.org/wiki/File:Flag_of_Azerbaijan.svg
Expand Down
117 changes: 117 additions & 0 deletions convert.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/env sh

echo "Options: w, width, h, height, n, normal, default"
echo -n "Enter your option: "
read OPTION

echo ""

echo "Options: yes, true, 1"
echo -n "Do you want to optimize the converted file? "
read OPTIPNGOP

updatealiases(){
echo "Updating aliases!"
IFS=' '
while read dst src; do
for dir in png; do
s="$dir/$src.$dir"
d="$dir/$dst.$dir"
cp -f "$s" "$d"
done
done < data/ALIASES
}

rsvgconvert() {
case $OPTIPNGOP in
"yes" | "true" | "1")
echo "Converting svg/$region.svg to png/$region.png.tmp"
if ! rsvg-convert $1 -f png -o "png/$region.png.tmp" "svg/$region.svg"; then
echo "ERROR rsvg-convert failed."
rm -f "png/$region.png.tmp"
else
echo "Optimizing png/$region.png!"
if ! optipng -quiet "png/$region.png.tmp"; then
echo "ERROR: optipng failed."
rm -f "png/$region.png.tmp"
continue
else
mv "png/$region.png.tmp" "png/$region.png"
fi
fi
echo ""
;;

*)
echo "Converting svg/$region.svg to png/$region.png" && rsvg-convert $1 -f png -o "png/$region.png" "svg/$region.svg"
;;
esac
}

usersvgconvert() {

WIDTH=$1;
HEIGHT=$2;

if [ $WIDTH -ne 0 ]; then
IFS=' '
cat SOURCES |
while read region htmlurl ; do
if [ -f "svg/$region.svg" ]; then
rsvgconvert "-a -w ${WIDTH}"
else
echo "File svg/$region.svg doesn't exist!"
fi
done
fi

if [ $HEIGHT -ne 0 ]; then
IFS=' '
cat SOURCES |
while read region htmlurl ; do
if [ -f "svg/$region.svg" ]; then
rsvgconvert "-a -h ${HEIGHT}"
else
echo "File svg/$region.svg doesn't exist!"
fi
done
fi

if [ $WIDTH -eq 0 ] && [ $HEIGHT -eq 0 ]; then

IFS=' '
cat SOURCES |
while read region htmlurl ; do
if [ -f "svg/$region.svg" ]; then
rsvgconvert "-a"
else
echo "File svg/$region.svg doesn't exist!"
fi
done
fi

updatealiases
}


case $OPTION in
w | width)
echo -n "Enter the prefered width: "
read WIDTH
usersvgconvert ${WIDTH} 0
;;

h | height)
echo -n "Enter the prefered height: "
read HEIGHT
usersvgconvert 0 ${HEIGHT}
;;

n | normal | default)
usersvgconvert 0 0
;;

*)
echo "Unknown option!"
;;
esac
3 changes: 3 additions & 0 deletions data/ALIASES-WP
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Åland Islands Åland
Ascension Island Ascension Island PD
AU-ACT the Australian Capital Territory
AU-NT the Northern Territory
AU-VIC Victoria (Australia)
British Indian Ocean Territory the British Indian Ocean Territory
Brunei Darussalam Brunei
CA-NT the Northwest Territories
Expand Down
13 changes: 13 additions & 0 deletions data/iso-3166-2-au.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
; ISO 3166-2:AU
; Source: https://www.iso.org/obp/ui/#iso:code:3166:AU
; Extracted on: 20201128
;
; Subdivision category 3166-2 code Subdivision name Language code Romanization system Parent subdivision
territory AU-ACT Australian Capital Territory en
state AU-NSW New South Wales en
territory AU-NT Northern Territory en
state AU-QLD Queensland en
state AU-SA South Australia en
state AU-TAS Tasmania en
state AU-VIC Victoria en
state AU-WA Western Australia en
117 changes: 64 additions & 53 deletions download-wp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,68 @@ IFS=' '

cat SOURCES |
while read region htmlurl ; do

html="html/$region.html"
svg="svg/$region.svg"
png="png/$region.png"

if ! test -s "$html"; then
rm -f "$html" "$svg" "$png"
echo "Downloading: $region $htmlurl"
if ! wget -q -O "$html" "${htmlurl}"; then
echo "ERROR: failed downloading html: ${htmlurl}"
continue
fi
if ! grep -q public_domain $html; then
echo "WARNING: flag NOT in public domain; check license"
fi
fi

if ! test -s "$svg"; then
svgurl=`cat "$html" | LANG=C sed 's@.*href="\(https://upload.wikimedia.org/wikipedia/commons/[^"]*[.]svg\)".*@\1@' | grep '^https://upload.wikimedia.org' | grep -v '/archive/' | head -n1`
if test "x$svgurl" = x; then
echo "ERROR: cannot find SVG URL in $html"
continue
fi
svgdata="`wget -q -O - "$svgurl"`"
if test "x$svgdata" = x; then
echo "ERROR: failed downloading SVG: $svgurl"
continue
fi
echo "$svgdata" > $svg.dos
if ! (dos2unix -q $svg.dos || fromdos $svg.dos); then
echo "ERROR: dos2unix failed."
#XXX rm -f $svg.dos
continue
else
mv $svg.dos $svg
fi
fi

if ! test -s "$png"; then
if ! rsvg-convert $svg > $png.tmp; then
echo "ERROR rsvg-convert failed."
rm -f $png.tmp
continue
fi
if ! optipng -quiet $png.tmp; then
echo "ERROR: optipng failed."
rm -f $png.tmp
continue
else
mv $png.tmp $png
fi
fi


html="html/$region.html"
svg="svg/$region.svg"
png="png/$region.png"

if ! test -s "$html"; then
rm -f "$html" "$svg" "$png"
echo "Downloading: $region $htmlurl"
if ! wget -q -O "$html" "${htmlurl}"; then
echo "ERROR: failed downloading html: ${htmlurl}"
continue
fi
if ! grep -q public_domain $html; then
echo "WARNING: flag NOT in public domain; check license"
fi
fi

if ! test -s "$svg"; then
svgurl=`cat "$html" | LANG=C sed 's@.*href="\(https://upload.wikimedia.org/wikipedia/commons/[^"]*[.]svg\)".*@\1@' | grep '^https://upload.wikimedia.org' | grep -v '/archive/' | head -n1`
if test "x$svgurl" = x; then
echo "ERROR: cannot find SVG URL in $html"
continue
fi
svgdata="`wget -q -O - "$svgurl"`"
if test "x$svgdata" = x; then
echo "ERROR: failed downloading SVG: $svgurl"
continue
fi
echo "$svgdata" > $svg.dos
if ! (dos2unix -q $svg.dos || fromdos $svg.dos); then
echo "ERROR: dos2unix failed."
#XXX rm -f $svg.dos
continue
else
mv $svg.dos $svg
fi
fi

case $1 in
"true" | "yes")
if ! test -s "$png"; then
echo "Converting $svg to $png.tmp"
if ! rsvg-convert $svg > $png.tmp; then
echo "ERROR rsvg-convert failed."
rm -f $png.tmp
continue
else
echo "Optimizing $png!"
if ! optipng -quiet $png.tmp; then
echo "ERROR: optipng failed."
rm -f $png.tmp
continue
else
mv $png.tmp $png
fi
fi
fi
;;

*)
continue
;;
esac
echo ""
done
Loading

0 comments on commit c2c1061

Please sign in to comment.