Comments (7)
Hey @bradenbest
I appreciate it that you are taking your time to point out the issues in the code. And I whole hearted-ly agree that there is redundancy in the code(I mean a lot!). I mean I just hacked it up under one night and this was barely working. These issues make it hard to maintain the code and I agree to it.
However a lot of things like BeautifulSoup
, pythonmagic
are not necessary here. So a lot of rewrite is required here.
When I wrote the initial release for this, I wasn't aware of the fact that xkcd had an API to it. So if anybody were to get the latest issue of the xkcd and the relevant information would be provided by requesting the url : http://xkcd.com/info.0.json
It would return back something like this,
{
"month": "1",
"num": 1632,
"link": "",
"year": "2016",
"news": "",
"safe_title": "Palindrome",
"transcript": "",
"alt": "I hope that somewhere in the world, \"Panamax\" is the last option on a \"size\" drop-down menu on a sex toy site.",
"img": "http:\/\/imgs.xkcd.com\/comics\/palindrome.png",
"title": "Palindrome",
"day": "20"
}
And similarly for comic number 1 we can request http://xkcd.com/1/info.0.json. And it will return back
{
"month": "1",
"num": 1,
"link": "",
"year": "2006",
"news": "",
"safe_title": "Barrel - Part 1",
"transcript": "[[A boy sits in a barrel which is floating in an ocean.]]\nBoy: I wonder where I'll float next?\n[[The barrel drifts into the distance. Nothing else can be seen.]]\n{{Alt: Don't we all.}}",
"alt": "Don't we all.",
"img": "http:\/\/imgs.xkcd.com\/comics\/barrel_cropped_(1).jpg",
"title": "Barrel - Part 1",
"day": "1"
}
So simply using requests
, we can do the whole thing.
So I can see a massive rewrite coming up.
If anybody is up and willing to take part in some of the action, I will divide the work parts with him.
Any other suggestions would be more than welcome
from xkcd-dl.
@prodicus I can try, but gosh, I haven't programmed in python in a while. The last big one I did was an html scraper called ngdl, that worked by grabbing the first url that matched "alternate"
, setting two pointers at the index of the match, and expanding outward until it hit the surrounding quotes, and copying that substring.
start = match
end = match
while(string[start] != '"') start -= 1
while(string[end] != '"') end += 1
return string[start:end - 1]
You know, the kind of silly/clever things you do when hacking things together.
Couldn't get cookies to work though. I was hoping I could spoof it, but I need cookiejar, which looks irritating to use.
And before that was a personal bookkeeping project where I used JSON to save data. I like JSON.
from xkcd-dl.
Also, what's __init__.py
supposed to be? I'm not familiar with python build systems (I usually use shell scripts or makefiles), so I'm not sure what it's purpose is, but it's 0 SLOC.
from xkcd-dl.
And if you're going to overhaul it, well, here's what I would do instead of simple refactoring:
- Start a new branch called '2.x' while keeping 1.x on the master branch for feedback, production, etc.
- Start developing the new version from scratch, start from version 2.0.0.
- When 2.x is usable and you feel it's functioning at or above the level of 1.x, change 2.x to the default branch, optionally rename master to 1.x.
This will keep major (incompatible) versions separate and will allow you to gracefully deprecate the first version while still allowing people to fetch it if they want. That's what I did with one of my projects.
from xkcd-dl.
@bradenbest I am gonna see if I would be able to start it soon.
As for __init__.py
, I would read all the links on the 1st page
https://www.google.co.in/?gfe_rd=cr&ei=glSgVumeLPKK8Qe88YrgDg#q=init.py+in+python
Now don't be so modest @bradenbest . Your projects look cool to me.
from xkcd-dl.
@prodicus So that's what it's for. You should definitely take advantage of it for the next update. As in, split the source between files that handle a task, and then have main.py
be a wrapper that gets installed to /usr/local/bin
, imports the package and all its xkcd-dl-related modules, and calls them.
Whoa, word salad. Here, I made a test implementation:
tree
.
├── main.py
└── phrase
├── get.py
├── __init__.py (empty)
└── say.py
1 directory, 7 files
main.py:
#!/usr/bin/env python
from phrase.say import *
sayphrase()
say.py:
from get import getphrase
def sayphrase():
print getphrase()
get.py:
def getphrase():
return "Hello World"
shell:
chmod +x main.py
./main.py
Hello World
from xkcd-dl.
looks like somebody is really excited eh!
Good one though.
from xkcd-dl.
Related Issues (16)
- prompt's `--update-db` when run in any other directory than the `HOME` directory HOT 1
- Example for --path argument not there in README
- Alt text not getting downloaded
- Sanitizing titles in the comic HOT 1
- Opening on the comic on the command line, options? HOT 12
- Ability to open xkcd's from the terminal HOT 1
- Version 0.1.0 - Unknown references to version, VERSION and __version__ HOT 2
- urllib.request issue HOT 4
- XKCD 961 Eternal Flame animated gif HOT 10
- Adding tests to xkcd-dl HOT 4
- 404 in the xkcd_dl website HOT 1
- Crashes randomly
- Installed, but after that nothing works.
- Does not work out of the box, if at all HOT 8
- Suggestions HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xkcd-dl.