Skip to content

Commit

Permalink
Bash script to create a large CSV file.
Browse files Browse the repository at this point in the history
  • Loading branch information
vaughany committed Jul 31, 2020
1 parent b53ff6d commit e2a7fb9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test-large.csv
43 changes: 43 additions & 0 deletions create-large-csv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

# Each 'run' generates 10 unique URLs, so if RUNS=10 you'll get 100 lines out.
# Uses the command `gpw` to create random-ish data. This is not installed by default: `sudo apt-get install gpw`

TIME_START=$(date +%s)
FILE=test-large.csv
RUNS=1000

if test -f "$FILE"; then
truncate -s 0 $FILE
else
touch $FILE
fi

for (( i=1; i <= $RUNS; i++)); do
string=$(gpw 1 25)
echo "http://$string.co.uk" >> $FILE
echo "http://$string.net" >> $FILE
echo "http://$string.org" >> $FILE
echo "http://$string.org.uk" >> $FILE
echo "http://$string.eu" >> $FILE
echo "http://$string.ie" >> $FILE
echo "http://$string.irish" >> $FILE
echo "http://$string.cymru" >> $FILE
echo "http://$string.wales" >> $FILE
echo "http://$string.scot" >> $FILE

if [[ $(( $i % 100 )) -eq "0" ]]; then
echo "Done $(wc -l $FILE | cut -d " " -f 1) lines."
fi
done

TIME_TAKEN=$(( ($(date +%s) - $TIME_START) ))

echo
echo "$(wc -l $FILE | cut -d " " -f 1) lines."

echo
ls -gh $FILE

echo
echo "Took ${TIME_TAKEN}s."
4 changes: 2 additions & 2 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Plugin Name: Bulk Import and Shorten
Plugin URI: https://github.com/vaughany/yourls-bulk-import-and-shorten
Description: A YOURLS plugin allowing importing of URLs in bulk to be shortened or (optionally) with a custom short URL.
Version: 0.3
Release date: 2020-07-25
Version: 0.4
Release date: 2020-07-31
Author: Paul Vaughan
Author URI: http://github.com/vaughany/
*/
Expand Down
13 changes: 7 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Plugin for [YOURLS](http://yourls.org) 1.7.x.

* Plugin URI: [github.com/vaughany/yourls-bulk-import-and-shorten](https://github.com/vaughany/yourls-bulk-import-and-shorten)
* Description: A YOURLS plugin allowing importing of URLs in bulk to be shortened or (optionally) with a custom short URL.
* Version: 0.3
* Release date: 2020-07-25
* Version: 0.4
* Release date: 2020-07-31
* Author: Paul Vaughan
* Author URI: [github.com/vaughany](http://github.com/vaughany/)

Expand Down Expand Up @@ -116,14 +116,15 @@ I'm always keen to add new features, improve performance and squash bugs, so if

## To-Do

* Make the forcing of titles to either generated from the URL or specified in the CSV file optional, so that YOURLS can try to pull one from the URL's website's HTML (which is probably the preferred option, but slow when doing huge imports).
* Make theforcing of titles to either generated from the URL or specified in the CSV file optional, so that YOURLS can try to pull one from the URL's website's HTML (which is probably the preferred option, but slow when doing huge imports).


## History

* 2020-07-25, v0.3: Going through the issues on GitHub and saw #3 which looked like an easy addition, so now if a third, optional field is specified in the URL, that is used as a title.
* 2020-07-25, v0.2: From a bug report via email about it running slowly processing thousands of rows, I've attempted a 'fix' by creating a title from the URL and passing that to the YOURLS function that would otherwise attempt to fetch one from the URL's HTML.
* 2014-07-17, v0.1: Still a work in progress.
* **2020-07-31, v0.4:** No meaningful code changes, but added a small Bash (Linux) script to make a large single-column CSV file for testing. You should be able to run it within Bash with `./create-large-csv.sh`. You might have to `chmod +x create-large-csv.sh` first.
* **2020-07-25, v0.3:** Going through the issues on GitHub and saw #3 which looked like an easy addition, so now if a third, optional field is specified in the URL, that is used as a title.
* **2020-07-25, v0.2:** From a bug report via email about it running slowly processing thousands of rows, I've attempted a 'fix' by creating a title from the URL and passing that to the YOURLS function that would otherwise attempt to fetch one from the URL's HTML.
* **2014-07-17, v0.1:** Still a work in progress.

## Finally...

Expand Down

0 comments on commit e2a7fb9

Please sign in to comment.