Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
- Fix encoding issue in test script
- Check downloaded file is a zip file before proceeding
  • Loading branch information
aytee17 committed Dec 20, 2017
1 parent 497e4f7 commit 8f4d918
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
7 changes: 4 additions & 3 deletions scripts/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ def main():
jobs = []
for feed in feeds:
if 't' in feed and 'u' in feed and 'd' in feed['u']:
job = {'title': feed['t'],'url': feed['u']['d']}
job = {'title': feed['t'].encode('utf8'),'url': feed['u']['d']}
jobs.append(job)

for job in jobs:
title = "'" + job['title'] + "'".encode('utf8')
url = job['url'].encode('utf8')
title = "'" + job['title'].decode('utf-8') + "'"
title = title.encode('utf-8')
url = job['url'].encode('utf-8')
print(title)
print(url)
os.system('mkdir ' + title)
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/Loader.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import javafx.application.Application;
import org.json.JSONException;
import org.json.JSONObject;

Expand Down Expand Up @@ -75,6 +76,7 @@ private List<File> getFiles(File gtfsPath) {
try {
ZipFile zipFile = new ZipFile(gtfsPath);


File gtfsFolder = new File(gtfsPath.getParent() + System.getProperty("file.separator") + "GTFS");
gtfsFolder.mkdir();

Expand Down
18 changes: 14 additions & 4 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import org.apache.commons.cli.*;

import java.io.File;
import java.io.RandomAccessFile;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -17,8 +18,7 @@ public class Main {
public static final String URL_OPTION = "u";
public static final String DATABASE_OPTION = "d";
public static final String CMD_NAME = "gtsql";
public static final String FOOTER = "\nThis tool is used to generate an SQLite database from a GTFS feed. " +
"\nPlease report issues at https://github.com/aytee17/gtfs-to-sqlite";
public static final String FOOTER = "\nPlease report issues at https://github.com/aytee17/gtfs-to-sqlite";

public static void main(String[] args) {
try {
Expand Down Expand Up @@ -84,10 +84,20 @@ public static void main(String[] args) {
if (line.hasOption(URL_OPTION)) {
String gtfsURL = line.getOptionValue(URL_OPTION);
print("Downloading GTFS feed from: " + gtfsURL);
String zipPath = gtfsPath + System.getProperty("file.separator") + "GTFS.zip";
gtfsFile = IO.getFileFromURL(
gtfsPath + System.getProperty("file.separator") + "GTFS.zip",
zipPath,
gtfsURL,
true);

// Check if the download is a zip file
RandomAccessFile raf = new RandomAccessFile(zipPath, "r");
long magicNumber = raf.readInt();
raf.close();
if (magicNumber != 0x504B0304) {
throw new Exception("\nDownload is not a zip file.");
}

print("\nFeed downloaded.");
} else {
gtfsFile = new File(gtfsPath);
Expand All @@ -101,7 +111,7 @@ public static void main(String[] args) {
print(exception.getMessage() + "\n");
new HelpFormatter().printHelp(CMD_NAME, "", options, FOOTER, true);
}
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
print(e.getMessage());
print(FOOTER);
Expand Down

0 comments on commit 8f4d918

Please sign in to comment.