about summary refs log tree commit diff stats
path: root/src/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/python_api.c14
-rw-r--r--src/plugins/python_api.h4
-rw-r--r--src/plugins/python_plugins.c11
3 files changed, 16 insertions, 13 deletions
diff --git a/src/plugins/python_api.c b/src/plugins/python_api.c
index e0d54c1c..01f7f8bd 100644
--- a/src/plugins/python_api.c
+++ b/src/plugins/python_api.c
@@ -872,6 +872,20 @@ python_api_init(void)
 #endif
 }
 
+void
+python_init_prof(void)
+{
+#if PY_MAJOR_VERSION >= 3
+    PyImport_AppendInittab("prof", python_api_init);
+    Py_Initialize();
+    PyEval_InitThreads();
+#else
+    Py_Initialize();
+    PyEval_InitThreads();
+    python_api_init();
+#endif
+}
+
 static char*
 _python_plugin_name(void)
 {
diff --git a/src/plugins/python_api.h b/src/plugins/python_api.h
index 339ac06b..79280cc6 100644
--- a/src/plugins/python_api.h
+++ b/src/plugins/python_api.h
@@ -35,10 +35,8 @@
 #ifndef PYTHON_API_H
 #define PYTHON_API_H
 
-#include <Python.h>
-
 void python_env_init(void);
-PyMODINIT_FUNC python_api_init(void);
+void python_init_prof(void);
 void python_shutdown(void);
 
 void python_command_callback(PluginCommand *command, gchar **args);
diff --git a/src/plugins/python_plugins.c b/src/plugins/python_plugins.c
index 670dd46f..15e244e1 100644
--- a/src/plugins/python_plugins.c
+++ b/src/plugins/python_plugins.c
@@ -68,18 +68,9 @@ _unref_module(PyObject *module)
 void
 python_env_init(void)
 {
-
     loaded_modules = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_unref_module);
 
-#if PY_MAJOR_VERSION >= 3
-    PyImport_AppendInittab("prof", python_api_init);
-    Py_Initialize();
-    PyEval_InitThreads();
-#else
-    Py_Initialize();
-    PyEval_InitThreads();
-    python_api_init();
-#endif
+    python_init_prof();
 
     const char *ver = Py_GetVersion();
     cons_show("PYTHON: %s", ver);
{ color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
<!DOCTYPE PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/1/DTD/1-strict.dtd">
<html xmlns="http://www.w3.org/1999/" lang="en" xml:lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta name="application-name" content="getwtxt">
  <link rel="stylesheet" type="text/css" href="/css">
  <title>{{.Name}} - twtxt Registry</title>
</head>
<body>
  <div id="container">
    <div id="head">
      <h2>{{.Name}}</h2>
    </div>
    <div id="subhead">
      twtxt registry
    </div>
    <div id="info">
      Instance Owner:<br />
      <span style="padding-left:1em">{{.Owner}}</span><br />
      Mail:<br />
      <span style="padding-left:1em">{{.Mail}}</span><br />
    </div>
    <div id="body">
      <div id="desc">
        <p>{{.Desc}}</p>
      </div>
      <p>API base URL:</p>
        <pre><code>/api</code></pre>
      <p>Formats available:</p>
        <pre><code>/api/plain</code></pre>
      <p>Endpoints:</p>
        <pre><code>/api/plain/users
/api/plain/mentions
/api/plain/tweets
/api/plain/tags</code></pre>
      <p>Query by user:</p>
        <pre><code>$ curl '{{.URL}}/api/plain/users?q=foo'
foo               https://example.com/twtxt.txt     2019-05-09T08:42:23.000Z
foobar            https://example2.com/twtxt.txt    2019-03-14T19:23:00.000Z
foo_barrington    https://example3.com/twtxt.txt    2019-05-01T15:59:39.000Z</code></pre>
      <p>Query by tweet content:</p>
        <pre><code>$ curl '{{.URL}}/api/plain/tweets?q=getwtxt'
foo_barrington    https://example3.com/twtxt.txt    2019-04-30T06:00:09.000Z    I just built getwtxt, time to set it up!</code></pre>
      <p>Query by mention:</p>
        <pre><code>$ curl '{{.URL}}/api/plain/mentions?url=https://foobarrington.co.uk/twtxt.txt'
foo    https://example.com/twtxt.txt    2019-02-26T11:06:44.000Z    @&lt;foo_barrington https://example3.com/twtxt.txt&gt; Hey!! Are you still working on that project?</code></pre>
      <p>Query by tag:</p>
        <pre><code>$ curl '{{.URL}}/api/plain/tags/programming'
foo    https://example.com/twtxt.txt    2019-03-01T09:31:02.000Z    I love #programming!</code></pre>
      <p>Get latest 20 tweets:</p>
        <pre><code>$ curl '{{.URL}}/api/plain/tweets'
foobar    https://example2.com/twtxt.txt    2019-05-13T12:46:20.000Z    It's been a busy day at work!
...</code></pre>
      <p>Get all users:</p>
        <pre><code>$ curl '{{.URL}}/api/plain/users'
foo_barrington    https://example3.com/twtxt.txt    2018-11-21T18:31:00.000Z
...</code></pre>
      <p>Add new user by submitting a <code>POST</code> request. If both variables are not used, or the user already exists in this registry, the server will respond with <code>400 Bad Request</code></p>
        <pre><code>$ curl -X POST '{{.URL}}/api/plain/users?url=https://example3.com/twtxt.txt&amp;nickname=foo_barrington'
200 OK</code></pre>
    </div>
    <div id="foot">
      powered by <a href="https://github.com/getwtxt/getwtxt">getwtxt</a>
    </div>
  </div>
</body>
</html>