Skip to content

Commit

Permalink
Merge pull request #1 from aliciapj/master
Browse files Browse the repository at this point in the history
1 - Capturando a Bulbasaur
  • Loading branch information
EdelBlau authored Dec 12, 2019
2 parents e3109d4 + d1eb1d1 commit 382d314
Show file tree
Hide file tree
Showing 9 changed files with 3,590 additions and 111 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/venv
/.idea
*.pyc
*.csv
*.csv
/.vscode
307 changes: 268 additions & 39 deletions README.md

Large diffs are not rendered by default.

3,306 changes: 3,306 additions & 0 deletions tutorial/bulbasaur.html

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tutorial/pokedex.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{"id": "001", "name": "Bulbasaur", "description": "Bulbasaur can be seen napping in bright sunlight.\nThere is a seed on its back. By soaking up the sun's rays,\nthe seed grows progressively larger.", "evolution": ["001", "002", "003"], "type": ["Grass", "Poison"], "height": "0.7", "weight": "6.9"}
]
15 changes: 1 addition & 14 deletions tutorial/tutorial/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import scrapy


class PokemonItem(scrapy.Item):
# define the fields for your item here like:
id = scrapy.Field()
Expand All @@ -16,17 +17,3 @@ class PokemonItem(scrapy.Item):
weight = scrapy.Field()
evolution = scrapy.Field()
type = scrapy.Field()

class PokemonAttacksItem(scrapy.Item):
pokemon_id = scrapy.Field()
attack_list = scrapy.Field()

class AttackItem(scrapy.Item):
name = scrapy.Field()
type = scrapy.Field()
# power = scrapy.Field()
# accuracy = scrapy.Field()
# effect = scrapy.Field()



19 changes: 2 additions & 17 deletions tutorial/tutorial/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,7 @@
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html

from neo4j import GraphDatabase, basic_auth
from neomodel import StructuredNode, StringProperty, RelationshipTo, RelationshipFrom, config

class PokemonPipeline(object):

class TutorialPipeline(object):
def process_item(self, item, spider):
driver = GraphDatabase.driver("bolt://localhost:7687", auth=basic_auth("neo4j", "pokemon12345"))
session = driver.session()

print("pokemon_id: " + item['id'])
query = "MERGE (p_%s:Pokemon {id:'%s', name:'%s', height:%s, weight:%s})" % (item['id'], item['id'], item['name'], item['height'], item['weight'])
session.run(query)
for evolution in item['evolution']:
if int(item['id']) != int(evolution):
query_2 = "MATCH (p_%s:Pokemon {id:'%s'}) MATCH (p_%s:Pokemon {id:'%s'}) MERGE (p_%s)-[:EVOLUTION]->(p_%s);" % (item['id'],item['id'], evolution, evolution, evolution, item['id'])
session.run(query_2)
session.close()

return item
return item
6 changes: 3 additions & 3 deletions tutorial/tutorial/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@

# Configure item pipelines
# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html
ITEM_PIPELINES = {
'tutorial.pipelines.PokemonPipeline': 300,
}
#ITEM_PIPELINES = {
# 'tutorial.pipelines.TutorialPipeline': 300,
#}

# Enable and configure the AutoThrottle extension (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/autothrottle.html
Expand Down
30 changes: 0 additions & 30 deletions tutorial/tutorial/spiders/attacks.py

This file was deleted.

12 changes: 5 additions & 7 deletions tutorial/tutorial/spiders/pokedex.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ def parse(self, response):
pokemon['description'] = response.css('div.version-descriptions p.active::text').extract_first().strip()
pokemon['evolution'] = response.css('section.pokedex-pokemon-evolution li span::text').re('[0-9]{3}')
pokemon['type'] = response.css('div.pokedex-pokemon-attributes div.dtm-type ul')[0].css("li a::text").extract()
pokemon['height'] = response.css('div.pokemon-ability-info ul li')[0].css("span.attribute-value::text").re_first('\d{1,2}[\,\.]{1}\d{1,2}').replace(",", ".")
pokemon['weight'] = response.css('div.pokemon-ability-info ul li')[1].css("span.attribute-value::text").re_first('\d{1,2}[\,\.]{1}\d{1,2}').replace(",", ".")
pokemon['height'] = response.css('div.pokemon-ability-info ul li')[0]\
.css("span.attribute-value::text").re_first(r'\d{1,2}[\,\.]{1}\d{1,2}').replace(",", ".")
pokemon['weight'] = response.css('div.pokemon-ability-info ul li')[1]\
.css("span.attribute-value::text").re_first(r'\d{1,2}[\,\.]{1}\d{1,2}').replace(",", ".")

# next pokemon
url = response.css("div.pokedex-pokemon-pagination a.next::attr(href)").extract_first()
yield Request(urljoin("https://www.pokemon.com", url), callback=self.parse)

yield pokemon
yield pokemon

0 comments on commit 382d314

Please sign in to comment.