Coder Social home page Coder Social logo

Needs cleanup about xkcd-dl HOT 7 CLOSED

tasdikrahman avatar tasdikrahman commented on May 20, 2024
Needs cleanup

from xkcd-dl.

Comments (7)

tasdikrahman avatar tasdikrahman commented on May 20, 2024

Hey @bradenbest

Referring to #10 and #6

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 😄

@prodicus

from xkcd-dl.

bradenbest avatar bradenbest commented on May 20, 2024

@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.

bradenbest avatar bradenbest commented on May 20, 2024

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.

bradenbest avatar bradenbest commented on May 20, 2024

And if you're going to overhaul it, well, here's what I would do instead of simple refactoring:

  1. Start a new branch called '2.x' while keeping 1.x on the master branch for feedback, production, etc.
  2. Start developing the new version from scratch, start from version 2.0.0.
  3. 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.

tasdikrahman avatar tasdikrahman commented on May 20, 2024

@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. 😄 . Meanwhile, you can start working on it if you wish.

from xkcd-dl.

bradenbest avatar bradenbest commented on May 20, 2024

@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.

tasdikrahman avatar tasdikrahman commented on May 20, 2024

looks like somebody is really excited eh! 💃

Good one though. 😄

from xkcd-dl.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.