Raised This Month: $9 Target: $400
 2% 

Reddit Puns using Python


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   ALL        Category:   Fun Stuff       
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 12-12-2020 , 03:58   Reddit Puns using Python
Reply With Quote #1

Test plugin of https://forums.alliedmods.net/showthread.php?t=329181
Command: /pun


Python script
Code:
import sys
import time
import datetime
import random
import requests
import socket
from fake_useragent import UserAgent

host = ''
port = 54500
url = "https://www.reddit.com/r/oneliners/randomrising/.json?kind=t3"

s = socket.socket()
s.bind((host, port))

s.listen(32)
conn, address = s.accept()
print("Connection from: " + str(address))

def memes():
    global data
    global conn

    ua = UserAgent()
    response = requests.get(url, headers={'User-agent': ua.random})

    if response.ok:
        output = response.json()['data']['children']
        
        for child in range(25):
            json = output[child]['data']
            
            if json:
                print (json['title'])
                conn.send(json['title'].encode())
                break

while True:
    data = conn.recv(256).decode()
    if not data:
        break
    print("from connected user: " + str(data))
    memes()
Plugin
Code:
#include <amxmodx> #include <sockets> #define LOCAL "localhost" #define PORT 54500 new s, error, data[128]; new dot[] = '.'; public plugin_init(){     register_clcmd("say /pun", "clcmd_pun"); } public plugin_cfg(){     s = socket_open(LOCAL, PORT, SOCKET_TCP, error);     if (!error){         set_task(0.1, "get_data", .flags="b");         data = "connected";         socket_send(s, data, charsmax(data));     } } public clcmd_pun(){     socket_send(s, dot, charsmax(dot)); } public get_data(){     if (socket_is_readable(s)){         socket_recv(s, data, charsmax(data));         client_print(0, print_chat, "%s", data);     } }
__________________

Last edited by Relaxing; 12-12-2020 at 03:58.
Relaxing is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 12-12-2020 , 04:02   Re: Reddit Puns using Python
Reply With Quote #2

Fake UserAgent is required
https://pypi.org/project/fake-useragent/
easy-install pip3 install fake-useragent
__________________

Last edited by Relaxing; 12-12-2020 at 04:02.
Relaxing is offline
Alber9091
Veteran Member
Join Date: Jun 2014
Location: Pakistan
Old 12-12-2020 , 12:30   Re: Reddit Puns using Python
Reply With Quote #3

Great !!
__________________
Alber9091 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-12-2020 , 18:36   Re: Reddit Puns using Python
Reply With Quote #4

If you're going to release a plugin, you should probably explain what in the world it is supposed to do. Also, what is the point of posting Python code?
__________________
fysiks is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 12-13-2020 , 20:09   Re: Reddit Puns using Python
Reply With Quote #5

The plugin fetches a pun from the reddit page r/oneliners using the inter-process communication with Python which gets the json format of rising posts and prints a random joke on the chat.
It's more likely a test plugin that can open a limitless amount of plugin ideas interacting with Python, such as checking the local wether, latest news, amxx updates, youtube api, sending email though a huge list of open source libraries.
__________________
Relaxing is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-13-2020 , 22:03   Re: Reddit Puns using Python
Reply With Quote #6

If it's a "test" plugin then you shouldn't release it as a new plugin submission, simply provide it with the post in Code Snippets/Tutorials (since that's what you just said it actually is). Also, you should provide your explanation with the plugin post so that people can understand what it does.
__________________
fysiks is offline
Relaxing
AlliedModders Donor
Join Date: Jun 2016
Location: White Plains
Old 02-01-2021 , 03:50   Re: Reddit Puns using Python
Reply With Quote #7

You're right, it doesn't belong to this subforum nor intented to be a plugin.
__________________
Relaxing is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-21-2021 , 05:56   Re: Reddit Puns using Python
Reply With Quote #8

Moved to tutorials section.
__________________
HamletEagle is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 21:11.


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode