Commit fd177757 authored by tsukumi's avatar tsukumi

Refactor: code format

parent 74565dd8
import argparse import argparse
import asyncio import asyncio
import json import json
...@@ -7,7 +8,7 @@ import time ...@@ -7,7 +8,7 @@ import time
from aiohttp import web from aiohttp import web
import daemon import daemon
from db import connect, Database from database import connect, Database
from log import log, add_file_handler, set_log_level, shutdown_logging from log import log, add_file_handler, set_log_level, shutdown_logging
from twitter_session import TwitterSession from twitter_session import TwitterSession
......
import copy import copy
from time import sleep
from pymongo import MongoClient from pymongo import MongoClient
from time import sleep
from log import log from log import log
......
# Count amount of "possibly_sensitive_editable" and "possibly_sensitive"
# flagged tweets in user's timeline
async def count_sensitives(session, user_id):
profile_timeline = await session.get_profile_tweets_raw(user_id)
profile_tweets = profile_timeline["globalObjects"]["tweets"].values()
counted = len(profile_tweets)
possibly_sensitive = len([1 for tweet in profile_tweets if "possibly_sensitive" in tweet.keys()])
possibly_sensitive_editable = len([1 for tweet in profile_tweets if "possibly_sensitive_editable" in tweet.keys()])
result = {
"counted": counted,
"possibly_sensitive": possibly_sensitive,
"possibly_sensitive_editable": possibly_sensitive_editable
}
return result
import gzip import gzip
import logging import logging
from logging.handlers import TimedRotatingFileHandler
import os import os
import shutil import shutil
from logging.handlers import TimedRotatingFileHandler
log_format = '%(asctime)s | %(module)s:%(lineno)d | %(levelname)s: %(message)s' log_format = '%(asctime)s | %(module)s:%(lineno)d | %(levelname)s: %(message)s'
logging.basicConfig(format=log_format) logging.basicConfig(format=log_format)
......
from tests.typeahead import test as test_typeahead from tests.typeahead import test as test_typeahead
from tests.ghostban import test as test_ghost_ban from tests.ghostban import test as test_ghost_ban
from tests.reply_deboosting import test as test_reply_deboosting from tests.reply_deboosting import test as test_reply_deboosting
......
import traceback import traceback
from log import log from log import log
......
import sys
import pathlib import pathlib
import sys
from typing import Any, Tuple, Dict from typing import Any, Tuple, Dict
sys.path.insert(0, str(pathlib.Path(__file__).parent)) sys.path.insert(0, str(pathlib.Path(__file__).parent))
from features import count_sensitives
from log import log from log import log
from util import is_error, is_generic_error, UnexpectedApiError from util import is_error, is_generic_error, UnexpectedApiError
# Count amount of "possibly_sensitive_editable" and "possibly_sensitive"
# flagged tweets in user's timeline
async def count_sensitives(session, user_id):
profile_timeline = await session.get_profile_tweets_raw(user_id)
profile_tweets = profile_timeline["globalObjects"]["tweets"].values()
counted = len(profile_tweets)
possibly_sensitive = len([1 for tweet in profile_tweets if "possibly_sensitive" in tweet.keys()])
possibly_sensitive_editable = len([1 for tweet in profile_tweets if "possibly_sensitive_editable" in tweet.keys()])
result = {
"counted": counted,
"possibly_sensitive": possibly_sensitive,
"possibly_sensitive_editable": possibly_sensitive_editable
}
return result
async def test(session, username: str) -> Tuple[str, Dict[str, Any]]: async def test(session, username: str) -> Tuple[str, Dict[str, Any]]:
profile: dict[str, Any] = {} profile: dict[str, Any] = {}
profile_raw = await session.profile_raw(username) profile_raw = await session.profile_raw(username)
......
import traceback import traceback
from log import log from log import log
......
import urllib.parse import urllib.parse
async def test(session, screen_name): async def test(session, screen_name):
......
from typing import Any
import os
import time import time
import urllib, urllib.parse import urllib, urllib.parse
import os from typing import Any
import aiohttp import aiohttp
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
......
def get_nested(obj, path, default=None): def get_nested(obj, path, default=None):
for p in path: for p in path:
if obj is None or not p in obj: if obj is None or not p in obj:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment