Coder Social home page Coder Social logo

python3 error about pullword HOT 1 CLOSED

finlay-liu avatar finlay-liu commented on July 27, 2024
python3 error

from pullword.

Comments (1)

ccx1997 avatar ccx1997 commented on July 27, 2024

To use the api in python3, you can replace the vanilla pullword.py content with the following code:

import requests
post_url = "http://api.pullword.com/post.php"

class ServerError(Exception):
     def __init__(self, value):
         self.value = value
     def __str__(self):
         return repr(self.value)

def split_word(words):
    words = words.split()
    words_list = []
    for i in words:
        if len(i) == 0:
            continue
        words_list.append(i.split(":"))
    return words_list


def pullword(source="", threshold=0, debug=1):
    payload = {"source":source, "param1":threshold, "param2":debug}
    pw = requests.post(post_url, data=payload)
    print(pw.url)
    if pw.status_code != 200:
        raise ServerError("server return %s"%pw.status_code)
    words = pw.content.decode()
    print(words)
    return split_word(words)

Then you can do like the following demo:

from pullword.pullword import pullword
res = pullword(u'其实我天生奔放贪玩', debug=1, threshold=0.7)
print(res)

So everything is OK!

from pullword.

Related Issues (3)

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.