-
Notifications
You must be signed in to change notification settings - Fork 49
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
Added Google Log Puzzle Challenge #344
Open
its-ChaTTy
wants to merge
2
commits into
PyAr:main
Choose a base branch
from
its-ChaTTy:logpuzzle
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
=============================================== | ||
Ejercicio de rompecabezas de registro de Google | ||
=============================================== | ||
|
||
.. datafile:: animal_code.google.com | ||
:fromfile: ./_static/animal_code.google.com | ||
:hide: | ||
|
||
|
||
|
||
|
||
.. activecode:: reto06 | ||
:nocodelens: | ||
|
||
Dado un archivo de registro de Apache, busque las URL del rompecabezas. | ||
|
||
Así es como se ve una URL de rompecabezas: | ||
10.254.254.28 - - [06/Aug/2007:00:13:48 -0700] "GET /~foo/puzzle-bar-aaab.jpg HTTP/1.0" 302 528 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" | ||
|
||
La salida de la función debe ser una lista de URL del formulario: | ||
['http://languages/edu/languages/google-python-class/images/puzzle/a-baaa.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baab.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baac.jpg', ...] | ||
|
||
|
||
~~~~ | ||
import re | ||
|
||
def read_urls(filename): | ||
"""Lee el texto de registro del archivo proporcionado y devuelve una lista de URL de rompecabezas en el orden ordenado.""" | ||
url_dict = {} | ||
# +++tu código aquí+++ | ||
|
||
|
||
def main(): | ||
img_urls = read_urls('animal_code.google.com') | ||
return img_urls | ||
|
||
img_urls= main() | ||
|
||
==== | ||
|
||
from unittest.gui import TestCaseGui | ||
|
||
class myTests(TestCaseGui): | ||
|
||
def testOne(self): | ||
answerAnimal= ['http://languages/edu/languages/google-python-class/images/puzzle/a-baaa.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baab.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baac.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baad.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baae.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baaf.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baag.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baah.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baai.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baaj.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baba.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babb.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babc.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babd.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babe.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babf.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babg.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babh.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babi.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babj.jpg'] | ||
self.assertEqual(answerAnimal, img_urls) | ||
|
||
myTests().main() | ||
|
||
|
||
|Licencia Creative Commons| | ||
Este trabajo tiene licencia `Creative Commons Attribution 4.0 | ||
International License <http://creativecommons.org/licenses/by/4.0/>`__. | ||
|
||
.. |Licencia Creative Commons| image:: https://i.creativecommons.org/l/by/4.0/88x31.png | ||
:target: http://creativecommons.org/licenses/by/4.0/ | ||
|
||
|
||
|
||
El ejercicio original se puede encontrar en `Google Log Puzzle Exercise <https://developers.google.com/edu/python/exercises/log-puzzle?hl=en>`__. | ||
|
||
|
||
.. Código correcto para fines de prueba: | ||
.. import re | ||
|
||
.. def read_urls(filename): | ||
.. """Lee el texto de registro del archivo proporcionado y devuelve una lista de URL de rompecabezas en el orden ordenado.""" | ||
.. url_dict = {} | ||
.. with open(filename, 'r') as file: | ||
.. log_text = file.read() | ||
|
||
.. lines = log_text.split('\n') | ||
.. for line in lines: | ||
.. match = re.search(r'"GET (\S+)', line) | ||
.. if match: | ||
.. path = match.group(1) | ||
.. if 'puzzle' in path: | ||
.. host = path.split('/')[2] | ||
.. url_dict['http://' + host + path] = 1 | ||
|
||
.. return sorted(url_dict.keys(), key=lambda url: re.search(r'-(\w+)-(\w+)\.\w+', url).group(2) if re.search(r'-(\w+)-(\w+)\.\w+', url) else url) | ||
|
||
.. def main(): | ||
.. # Read URLs from log texts | ||
.. img_urls = read_urls('animal_code.google.com') | ||
.. print(img_urls) | ||
.. return img_urls | ||
|
||
.. # Run the main function | ||
.. img_urls= main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
========================== | ||
Google Log Puzzle Exercise | ||
========================== | ||
|
||
.. datafile:: animal_code_en.google.com | ||
:fromfile: ./_static/animal_code.google.com | ||
:hide: | ||
|
||
|
||
|
||
|
||
.. activecode:: reto06_en | ||
:nocodelens: | ||
|
||
Given an apache logfile, find the puzzle urls. | ||
|
||
Here's what a puzzle url looks like: | ||
10.254.254.28 - - [06/Aug/2007:00:13:48 -0700] "GET /~foo/puzzle-bar-aaab.jpg HTTP/1.0" 302 528 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6" | ||
|
||
The output of the function should be a list of urls of the form: | ||
['http://languages/edu/languages/google-python-class/images/puzzle/a-baaa.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baab.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baac.jpg', ...] | ||
|
||
|
||
~~~~ | ||
import re | ||
|
||
def read_urls(filename): | ||
"""Reads the log text from the given file and returns a list of puzzle URLs in the sorted order.""" | ||
url_dict = {} | ||
# +++your code here+++ | ||
|
||
|
||
def main(): | ||
img_urls = read_urls('animal_code_en.google.com') | ||
return img_urls | ||
|
||
img_urls= main() | ||
|
||
==== | ||
|
||
from unittest.gui import TestCaseGui | ||
|
||
class myTests(TestCaseGui): | ||
|
||
def testOne(self): | ||
answerAnimal= ['http://languages/edu/languages/google-python-class/images/puzzle/a-baaa.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baab.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baac.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baad.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baae.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baaf.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baag.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baah.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baai.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baaj.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-baba.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babb.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babc.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babd.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babe.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babf.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babg.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babh.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babi.jpg', 'http://languages/edu/languages/google-python-class/images/puzzle/a-babj.jpg'] | ||
self.assertEqual(answerAnimal, img_urls) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no appropriate error message |
||
|
||
myTests().main() | ||
|
||
|
||
|Creative Commons License| | ||
This work is licensed under a `Creative Commons Attribution 4.0 | ||
International License <http://creativecommons.org/licenses/by/4.0/>`__. | ||
|
||
.. |Creative Commons License| image:: https://i.creativecommons.org/l/by/4.0/88x31.png | ||
:target: http://creativecommons.org/licenses/by/4.0/ | ||
|
||
|
||
|
||
Original exercise can be found at `Google Log Puzzle Exercise <https://developers.google.com/edu/python/exercises/log-puzzle?hl=en>`__. | ||
|
||
|
||
.. Correct code for test purposes: | ||
.. import re | ||
|
||
.. def read_urls(filename): | ||
.. """Reads the log text from the given file and returns a list of puzzle URLs in sorted order.""" | ||
.. url_dict = {} | ||
.. with open(filename, 'r') as file: | ||
.. log_text = file.read() | ||
|
||
.. lines = log_text.split('\n') | ||
.. for line in lines: | ||
.. match = re.search(r'"GET (\S+)', line) | ||
.. if match: | ||
.. path = match.group(1) | ||
.. if 'puzzle' in path: | ||
.. host = path.split('/')[2] | ||
.. url_dict['http://' + host + path] = 1 | ||
|
||
.. return sorted(url_dict.keys(), key=lambda url: re.search(r'-(\w+)-(\w+)\.\w+', url).group(2) if re.search(r'-(\w+)-(\w+)\.\w+', url) else url) | ||
|
||
.. def main(): | ||
.. # Read URLs from log texts | ||
.. img_urls = read_urls('animal_code_en.google.com') | ||
.. print(img_urls) | ||
.. return img_urls | ||
|
||
.. # Run the main function | ||
.. img_urls= main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no appropriate error message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing that out, would have missed it. I have added the Test Note now.