Skip to content

Instantly share code, notes, and snippets.

View Mec-iS's full-sized avatar

Lorenzo Mec-iS

View GitHub Profile
@Mec-iS
Mec-iS / nasasearch.json
Created August 14, 2014 20:19
Quickscrape's scrapers definition for nasasearch
{
"url": "nasasearch.nasa.gov",
"elements": {
"title": {
"selector": "//div[@id='search']/div[@id='results']/div[@class='searchresult']/h2/a",
"attribute": "text"
},
"link": {
"selector": "//div[@id='search']/div[@id='results']/div[@class='searchresult']/h2/a",
"attribute": "href"
@Mec-iS
Mec-iS / command.sh
Created August 14, 2014 20:22
Quickscrape's command for scraping nasasearch
quickscrape --url "http://nasasearch.nasa.gov/search?affiliate=nasa&query=nustar+x-ray&commit=Search" --scraper journal-scrapers/scrapers/nasasearch.json --output nasasearch --loglevel debug
@Mec-iS
Mec-iS / results.json
Created August 14, 2014 20:25
Quickscrape's test result
[
{
"title": "NuSTAR | NASA"
},
{
"title": "NuSTAR Delivers the X-Ray Goods | NASA"
},
{
"title": "NuSTAR Delivers the X-Ray Goods - NASA Jet Propulsion ..."
},
Three examples of RDF-SKOS definitions taken from http://www.sti.nasa.gov/sscg/main.html
1.TURTLE LANGUAGE, a keyword, a category and a division taken from NASA-STI:
Common prefixes:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
File 1:
<!-- defining a keyword as a Concept, at URI = http://mydomain.com/infrared+astronomy# -->
@Mec-iS
Mec-iS / definitions_astronomy.xml
Created September 12, 2014 09:59
example for an RDF-XML representation of the NASA-STI categories
<?xml version="1.0"?>
<!-- Definition of Category Astronomy -->
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:skos="http://www.w3.org/2004/02/skos/core#">
<skos:Concept rdf:about="http://mydomain.com/astronomy">
@Mec-iS
Mec-iS / rdflib-3-3.py
Created September 26, 2014 15:06
RDFlib example
##############################################################################################
# Py3.3 script to navigate DBpedia URIs
# install latest RDFlib with 'pip install rdflib'
# https://github.com/RDFLib/rdflib/
##############################################################################################
from rdflib import Graph, term
from rdflib.namespace import SKOS
{
"_id" : ObjectId("542dfd62d61fce6881caed5e"),
"http://www_w3_org/2004/02/skos/core#closeMatch" : [
{
"@id" : "http://dbpedia.org/data/Asteroid.jsond",
"_id" : ObjectId("542dfd62d61fce6881caed5d"),
"@type" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#resource"
}
],
"http://schema_org/provider" : {
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
@Mec-iS
Mec-iS / liarsdiceagent.py
Last active November 13, 2015 10:20
An agent to play Liar's Dice game, based on an API that serve information about a game been played by four players
"""
Experiment for an automated agent playing Liar's Dice.
It's a partial implementation, some possible moves are not yet implemented.
Work time spent: 9 hours, considering also the time taken to learn basic rules
of the game.
It won multiple games beating computer opponents with an average score of 27,
where the average score for computer winners were 25.
Version 0.1
# coding=utf-8
__author__ = 'Lorenzo'
from secret import _KEY
def post_curling(url, params, file=None, display=False):
"""
POST to a remote url and print the response in a file or on screen or return the body of the response
:param url: target url
:param params: parameters in the request