Skip to content

Instantly share code, notes, and snippets.

View enginebai's full-sized avatar
📈
Focusing, Learning, Improving, Evolving

Engine Bai enginebai

📈
Focusing, Learning, Improving, Evolving
View GitHub Profile
def send_fb_message(to, message):
post_message_url = 'https://graph.facebook.com/v2.6/me/messages?access_token={token}'.format(token=config.FB_TOKEN)
response_message = json.dumps({"recipient":{"id": to},
"message":{"text":message}})
req = requests.post(post_message_url,
headers={"Content-Type": "application/json"},
data=response_message)
print("[{}] Reply to {}: {}", req.status_code, to, message)
if __name__ == '__main__':
context = ('ssl/fullchain.pem', 'ssl/privkey.pem')
app.run(host='0.0.0.0', debug=True, ssl_context=context)
client.send_buttons(recipient_id, "You can find me with below", [
ActionButton(ButtonType.WEB_URL, "Blog", "http://blog.enginebai.com"),
ActionButton(ButtonType.POSTBACK, "Email", Intent.EMAIL)
])
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Server {
public static final int LISTEN_PORT = 5987;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Scanner;
public class Client {
public static void main(String[] args) throws IOException {
String host = "";
int port = 5987;
Socket socket = null;
public static BlockProperties parseWebContent(Parser parser) throws ParserException {
NodeList visualBlockNodeList = getVisualBlock(parser);
// Output.printNodeList( visualBlockNodeList );
NodeList linkNodeList = findLinkBlock(visualBlockNodeList);
NodeList invalidNodeList = findInvalidBlock(visualBlockNodeList);
NodeList actionNodeList = findActionBlock(visualBlockNodeList); // NOTE: 因為動作標籤可能沒有包含文字,所以要獨立出來找
Map<String, NodeList> blockNodeMap = new HashMap<String, NodeList>();
blockNodeMap.put(VISUAL_BLOCK, visualBlockNodeList);
blockNodeMap.put(LINK_BLOCK, linkNodeList);
data class Media(@SerializedName("media_id") val mediaId: String)
POST /test/api1
Authorization Bearer JWT
User-Agent: Make sure to include platform
---
200 OK
Content-Type: application/json
Location: MEDIA_UPLOAD_URL
{
object Api {
fun api1(): Observable<Response<Media>> =
ApiHelper.getApi().api1()
fun api2(uploadUrl: String): Observable<okhttp3.Response> =
Observable.fromCallable {
val request = Request.Builder()
.url(uploadUrl)
.build()
object ApiRepository {
fun chainApi1AndApi1(): Observable<okhttp3.Response> {
return Api.api1().flatMap { response1 ->
if (response1.isSuccessful) {
var uploadUrl = response1.headers().get(ApiUtils.Header.LOCATION)
uploadUrl?.let { url ->
Api.api2(url)
} ?: kotlin.run {
throw Exceptions.propagate(NullPointerException("Media upload URL is empty"))