Skip to content

Instantly share code, notes, and snippets.

@homebysix
Last active March 18, 2019 17:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save homebysix/9640c6a6eecff82d3b16 to your computer and use it in GitHub Desktop.
Save homebysix/9640c6a6eecff82d3b16 to your computer and use it in GitHub Desktop.
get_sourceforge_group_id.py
#!/usr/bin/env python
'''
Name: get_sourceforge_group_id.py
Description: Given the name of a SourceForge project, returns its group
ID. Useful for creating AutoPkg recipes that leverage the
SourceForgeURLProvider processor.
Author: Elliot Jordan <elliot@elliotjordan.com>
Created: 2015-07-11
Last Modified: 2015-07-11
Version: 1.0
'''
import urllib2
import json
project_name = raw_input("Please enter the project name from the SourceForge URL: ")
project_api_url = "https://sourceforge.net/rest/p/" + project_name
raw_json = urllib2.urlopen(project_api_url).read()
parsed_json = json.loads(raw_json)
for this_dict in parsed_json['tools']:
try:
this_dict['sourceforge_group_id']
except KeyError:
pass
else:
print this_dict['sourceforge_group_id']
#!/bin/sh
###
#
# Name: get_sourceforge_group_id.sh
# Description: Given the name of a SourceForge project, returns its group
# ID. Useful for creating AutoPkg recipes that leverage the
# SourceForgeURLProvider processor.
# Author: Elliot Jordan <elliot@elliotjordan.com>
# Created: 2015-07-11
# Last Modified: 2015-07-11
# Version: 1.0
#
###
printf "Please enter the project name from the SourceForge URL: "
read project_name
curl -s "https://sourceforge.net/rest/p/$project_name" \
| sed -e 's/[]{}[]//g' \
| awk -v RS=',' -F "\"sourceforge_group_id\": " '/sourceforge_group_id/{print $2}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment