Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read list of station or sensor identifiers from file #46

Open
amotl opened this issue Dec 11, 2022 · 1 comment
Open

Read list of station or sensor identifiers from file #46

amotl opened this issue Dec 11, 2022 · 1 comment

Comments

@amotl
Copy link
Member

amotl commented Dec 11, 2022

Hi there,

at 1, @ohobby asked about how he would be able to feed a list of sensor identifiers from a file to the luftdatenpumpe stations or luftdatenpumpe readings commands.

I could also provide a list in a file with the sensor_id’s. Is it possible to include this list in the query so I don’t have to type all sensor_id’s in the query?

Indeed, it would be sweet if Luftdatenpumpe provided such an option.

With kind regards,
Andreas.

Footnotes

  1. https://community.panodata.org/t/luftdatenpumpe-the-sensor-ids-on-weather-hiveeyes-org-are-different-from-those-of-sensor-community-respectively/254/6

@amotl
Copy link
Member Author

amotl commented Dec 11, 2022

Workaround

As a workaround, a few commands of Unix magic can be applied to the problem. This incantation will read the file sensor_ids.txt, containing a list of sensor identifiers, separated by newlines, and will reformat it to be comma-separated.

cat sensor_ids.txt | printf "%s" "$(< /dev/stdin)" | tr '\n' ','

In this way, it is suitable for feeding it to the --sensor= option of Luftdatenpumpe. Imagine you have a file sensor_ids.txt, you could use a wrapper program like ldipumpe.sh, attached below, by invoking ./ldipumpe.sh sensor_ids.txt --reverse-geocode --target=....

Wrapper program

#!/bin/bash
#
# Use Luftdatenpumpe to acquire data by list of
# sensor identifiers from file.
#
# Synopsis:
#
# ./ldipumpe.sh sensor_ids.txt --reverse-geocode
#

# Read input file name.
infile=$1
shift

# Sanity checks.
if [ -z "${infile}" ]; then
  echo "ERROR: No input file given"
  exit 1
fi

# Read and reformat text file to comma-separated list.
sensor_ids=$(cat "${infile}" | printf "%s" "$(< /dev/stdin)" | tr '\n' ',')
echo "Using sensor identifiers: ${sensor_ids}"

# Invoke Luftdatenpumpe with given sensor identifiers,
# forwarding other command line options.
luftdatenpumpe stations \
  --network=ldi --sensor="${sensor_ids}" \
  "$@"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant