Code Monkey home page Code Monkey logo

stack-overflow-import's Introduction

StackOverflow Importer

Do you ever feel like all you’re doing is copy/pasting from Stack Overflow?

Let’s take it one step further.

from stackoverflow import quick_sort will go through the search results
of [python] quick sort looking for the largest code block that doesn’t
syntax error in the highest voted answer from the highest voted question
and return it as a module. If that answer doesn’t have any valid python
code, it checks the next highest voted answer for code blocks.
>>> from stackoverflow import quick_sort, split_into_chunks

>>> print(quick_sort.sort([1, 3, 2, 5, 4]))
[1, 2, 3, 4, 5]

>>> print(list(split_into_chunks.chunk("very good chunk func")))
['very ', 'good ', 'chunk', ' func']

>>> print("I wonder who made split_into_chunks", split_into_chunks.__author__)
I wonder who made split_into_chunks https://stackoverflow.com/a/35107113

>>> print("but what's the license? Can I really use this?", quick_sort.__license__)
but what's the license? Can I really use this? CC BY-SA 3.0
>>> assert("nice, attribution!")

This module is licensed under whatever license you want it to be as long as the license is compatible with the fact that I blatantly copied multiple lines of code from the Python standard library.

stack-overflow-import's People

Contributors

drathier avatar joariski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stack-overflow-import's Issues

No longer works

In 2021 this package always fails to import things with the following error:

  File "/home/vadim0x60/.pyenv/versions/3.9.9/lib/python3.9/site-packages/stackoverflow/__init__.py", line 34, in find_spec
    code, author, url = cls.find_working_code(spec.name)
  File "/home/vadim0x60/.pyenv/versions/3.9.9/lib/python3.9/site-packages/stackoverflow/__init__.py", line 24, in find_working_code
    result = cls.fetch_code(url)
  File "/home/vadim0x60/.pyenv/versions/3.9.9/lib/python3.9/site-packages/stackoverflow/__init__.py", line 85, in fetch_code
    return cls.find_code_in_html(q.text)
  File "/home/vadim0x60/.pyenv/versions/3.9.9/lib/python3.9/site-packages/stackoverflow/__init__.py", line 94, in find_code_in_html
    answer.votes = int(answer.find(itemprop="upvoteCount")["data-value"])
TypeError: 'NoneType' object is not subscriptable

Tragic to see an essential part of my workflow completely fail me.

Is this a programming joke or not?

A colleague and I can't decide if this is a programming joke or if it is meant seriously. Could you please shed some light there? :)

PS: This isn't a meta-joke, it is a serious question.

Add `pip install`

Before this can be reliably used in production, this needs is the ability to auto-install necessary packages.

Details regarding Usage of the import

After Importing quicksort as mentioned before I didn't know what to pass as a parameter to the function.If some support of function definition details is added.It would be great.

Make the imported module callable

While this marvelous library is obviously saving everyone a lot of time going back and forth between SO, clipboard, and their IDE, I feel its usage is still not as straightforward as it could be.

For example, in this snippet:

from stackoverflow import split_into_chunks
print(list(split_into_chunks.chunk("very good chunk func")))

you still need to know to call a chunk function from the imported module. It could've been chunks, split, or whatever else (depending on what the SO answer chose), forcing the programmer to (gasp!) look at the code he or she imports and perhaps even understand it.

I'd suggest that the importer should be clever enough to pick the correct function for the programmer, and then make the imported symbol itself callable:

from stackoverflow import split_into_chunks
print(list(split_into_chunks("very good chunk func")))

The heuristics of making the correct choice are left as exercise for the reader.

Support star-imports

Even if it's not recommeded by PEP-8, from stackoverflow import * should still work.

Should be able to import itself from SO

Hi!
I'd consider this a feature request, stack-overflow-import should be able to import itself via stack overflow. e.g.

from stackoverflow import stackoverflow

This way stack-overflow-import users wouldn't need to go through downloading stack-overflow-import again.

Add proper licensing

"The PSF license was developed specifically and only for Python and its standard libraries. If you want to license your code for contribution to the PSF, do not use the PSF license; "

https://wiki.python.org/moin/PythonSoftwareFoundationLicenseFaq

I would suggest MIT, BSD, or maybe in this case WTFPL. Basically just add a permissive license file and mention of it in readme you're good to go.

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.