Stack-overflow-import - Import arbitrary code from Stack Overflow as Python modules.

Overview

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.
>> 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!")">
>>> 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.

Comments
  • Should be able to import itself from SO

    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.

    opened by filippog 3
  • Add proper licensing

    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.

    opened by cdgriffith 2
  • Add a security warning

    Add a security warning

    It may not be immediately obvious to less experienced programmers that this joke tool is also a shotgun aimed directly at their own face, and should be treated with caution.

    It might actually be better to have an interactive prompt that prints out the answer and requires console confirmation of the code in question before actually running code.

    opened by glyph 1
  • Caching for already resolved

    Caching for already resolved "questions"

    Making the requests to Stack Overflow on every run of the program is not efficient.

    Once a question/code piece was found and downloaded it should be cached.

    wontfix 
    opened by hvm2hvm 1
  • No longer works

    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.

    opened by vadim0x60 0
  • support more than one answer code detection

    support more than one answer code detection

    Test to find the two example unable to execute, which may because of the change of highest votes answer changed. Change the code to support more than one answer code detection

    opened by liminghao1630 1
  • Make the imported module callable

    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.

    opened by Xion 2
  • Is this a programming joke or not?

    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.

    opened by 7heo 9
Owner
Filip Haglund
Filip Haglund
Buffer overflow example for python

Buffer overflow example for python

Mehmet 1 Jan 4, 2022
Py4J enables Python programs to dynamically access arbitrary Java objects

Py4J Py4J enables Python programs running in a Python interpreter to dynamically access Java objects in a Java Virtual Machine. Methods are called as

Barthelemy Dagenais 1k Jan 2, 2023
Pdraw - Generate Deterministic, Procedural Artwork from Arbitrary Text

pdraw.py: Generate Deterministic, Procedural Artwork from Arbitrary Text pdraw a

Brian Schrader 2 Sep 12, 2022
Python communism - A module for initiating the communist revolution in each of our python modules

Python communist revolution A man once said to abolish the classes or something

null 758 Jan 3, 2023
Why write code when you can import it directly from GitHub Copilot?

Copilot Importer Why write code when you can import it directly from GitHub Copilot? What is Copilot Importer? The copilot python module will dynamica

Mythic 41 Jan 4, 2023
PDX Code Guild Full Stack Python Bootcamp starting 2022/02/28

Class Liger Rough Timeline Weeks 1, 2, 3, 4: Python Weeks 5, 6, 7, 8: HTML/CSS/Flask Weeks 9, 10, 11: Javascript Weeks 12, 13, 14, 15: Django Weeks 16

PDX Code Guild 5 Jul 5, 2022
A weekly dive into commonly used modules in the Rust ecosystem, with story flavor!

The goal of this project is to bring the same concept as PyMOTW to the Rust world. PyMOTW was an invaluable resource for me when I was learning Python years ago, and I hope that I can help someone in a similar way. Each week we'll dive into a module and explore some of the functionality that we can find there while following along the adventures of some colourful characters.

Scott Lyons 20 Aug 26, 2022
Reload all Blender add-on modules

Reload-Addon This add-on creates a list of the modules that the add-on selected in the drop-down menu contains and reloads them with the keyboard shor

null 2 Dec 2, 2021
This repository holds those infrastructure-level modules, that every application requires that follows the core 12-factor principles.

py-12f-common About This repository holds those infrastructure-level modules, that every application requires that follows the core 12-factor principl

Tamás Benke 1 Dec 15, 2022
Odoo modules related to website/webshop

Website Apps related to Odoo it's website/webshop features: webshop_public_prices: allow configuring to hide or show product prices and add to cart bu

Yenthe Van Ginneken 9 Nov 4, 2022
Voldemort's Python import helper

importmagician Voldemort's Python import helper pip install importmagician Import from uninstalled Python directories Say you have a directory (relat

Zhengyang Feng 4 Mar 9, 2022
It is convenient to quickly import Python packages from the network.

It is convenient to quickly import Python packages from the network.

zmaplex 1 Jan 18, 2022
Import some key/value data to Prometheus custom-built Node Exporter in Python

About the app In one particilar project, i had to import some key/value data to Prometheus. So i have decided to create my custom-built Node Exporter

Hamid Hosseinzadeh 1 May 19, 2022
A python package for batch import of resume attachments to be parsed in HrFlow.

HrFlow Importer Description A python package for batch import of resume attachments to be parsed in HrFlow. hrflow-importer is an open-source project

HrFlow.ai (ex: Riminder.net) 3 Nov 15, 2022
addon for blender to import mocap data from tools like easymocap, frankmocap and Vibe

b3d_mocap_import addon for blender to import mocap data from tools like easymocap, frankmocap and Vibe ==================VIBE================== To use

Carlos Barreto 97 Dec 7, 2022
YBlade - Import QBlade blades into Fusion 360

YBlade - Import QBlade blades into Fusion 360 Simple script for Fusion 360 that takes QBlade blade description and constructs the blade: Usage First,

Jan Mrázek 37 Sep 25, 2022
Blender addon to import images as meshes

ImagesAsMesh Blender addon to import images as meshes. Inspired by: ImagesAsPlanes Installation It's like just about every other Blender addon. Downlo

Niccolo Zuppichini 4 Jan 4, 2022
Import Apex legends mprt files exported from Legion

Apex-mprt-importer-for-Blender Import Apex legends mprt files exported from Legion. REQUIRES CAST IMPORTER Usage: Use a VPK extracter to extract the m

null 15 Dec 18, 2022
Interfaces between napari and pymeshlab library to allow import, export and construction of surfaces.

napari-pymeshlab Interfaces between napari and the pymeshlab library to allow import, export and construction of surfaces. This is a WIP and feature r

Zach Marin 4 Oct 12, 2022