· 6 years ago · Jan 04, 2019, 07:48 AM
1from jinja2 import Environment
2
3template = """
4POST /1.1/statuses/update.json?include_entities=true HTTP/1.1
5Accept: */*
6Connection: close
7User-Agent: OAuth gem v0.4.4
8Content-Type: application/x-www-form-urlencoded
9Authorization:
10OAuth oauth_consumer_key="{{ oauth_consumer_key }}",
11oauth_nonce="{{ oauth_nonce }}",
12oauth_signature="{{ oauth_signature }}",
13oauth_signature_method="{{ oauth_signature_method }}",
14oauth_timestamp="{{ oauth_timestamp }}",
15oauth_token="{{ oauth_token }}",
16oauth_version="{{ oauth_version }}"
17Content-Length: 76
18Host: api.twitter.com
19
20status={{ status | urlencode }}
21"""
22
23
24def build_request(template, keys):
25 return Environment().from_string(template).render(keys)
26
27
28if __name__ == '__main__':
29 keys = { "oauth_consumer_key":"xvz1evFS4wEEPTGEFPHBog",
30 "oauth_nonce":"kYjzVBB8Y0ZFabxSWbWovY3uYSQ2pTgmZeNu2VS4cg",
31 "oauth_signature":"tnnArxj06cWHq44gCs1OSKk%2FjLY%3D",
32 "oauth_signature_method":"HMAC-SHA1",
33 "oauth_timestamp":"1318622958",
34 "oauth_token":"370773112-GmHxMAgYyLbNEtIKZeRNFsMKPR9EyMZeS9weJAEb",
35 "oauth_version":"1.0",
36 "status" :"Muj prvni status na twitteru"}
37
38 print(build_request(template ,keys))